Practice Find Missing and Repeated Values
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
An n by n grid should contain integers 1 through n^2 once each, but one value appears twice and another is missing. Return [repeatedValue, missingValue].
Source: Find Missing and Repeated Values on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
grid = [[1,3],[2,2]]
Output
[2,4]
# Example 2
Input
grid = [[9,1,7],[8,9,2],[3,4,6]]
Output
[9,5]
Constraints
2 <= n == grid.length == grid[i].length <= 50
1 <= grid[i][j] <= n * n
For all x that 1 <= x <= n * n there is exactly one x that is not equal to any of the grid members.
For all x that 1 <= x <= n * n there is exactly one x that is equal to exactly two of the grid members.
For all x that 1 <= x <= n * n except two of them there is exactly one pair of i, j that 0 <= i, j <= n - 1 and grid[i][j] == x.
Related LeetCode Problems
Practice more problems similar to Find Missing and Repeated Values.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.