Tap here to switch tabs
Problem
Submissions

Problem: Find Missing and Repeated Values

med
30 min
Try to solve the Find Missing and Repeated Values problem.

Statement

You are given a square integer matrix grid of size n x n that is intended to contain every value from 11 to n2n^2 exactly once. However, one value appears twice in grid, and one value from the range 11 to n2n^2 does not appear at all.

Return an array of length 22 where the first element is the repeated value and the second element is the missing value.

Constraints:

  • 2≤2 \leq n ==== grid.length ==== grid[i].length ≤50\leq 50

  • 1≤1 \leq grid[i][j] ≤n⋅n\leq n \cdot n

  • For all x such that 1≤1 \leq x ≤n⋅n\leq n \cdot n, there exists exactly one x that is not equal to any value in grid

  • For all x such that 1≤1 \leq x ≤n⋅n\leq n \cdot n, there exists exactly one x that is equal to exactly 22 values in grid

  • For all x such that 1≤1 \leq x ≤n⋅n\leq n \cdot n except two of them, there exists exactly one pair i, j such that 0≤0 \leq i, j ≤n−1\leq n - 1 and grid[i][j] == x

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find Missing and Repeated Values

med
30 min
Try to solve the Find Missing and Repeated Values problem.

Statement

You are given a square integer matrix grid of size n x n that is intended to contain every value from 11 to n2n^2 exactly once. However, one value appears twice in grid, and one value from the range 11 to n2n^2 does not appear at all.

Return an array of length 22 where the first element is the repeated value and the second element is the missing value.

Constraints:

  • 2≤2 \leq n ==== grid.length ==== grid[i].length ≤50\leq 50

  • 1≤1 \leq grid[i][j] ≤n⋅n\leq n \cdot n

  • For all x such that 1≤1 \leq x ≤n⋅n\leq n \cdot n, there exists exactly one x that is not equal to any value in grid

  • For all x such that 1≤1 \leq x ≤n⋅n\leq n \cdot n, there exists exactly one x that is equal to exactly 22 values in grid

  • For all x such that 1≤1 \leq x ≤n⋅n\leq n \cdot n except two of them, there exists exactly one pair i, j such that 0≤0 \leq i, j ≤n−1\leq n - 1 and grid[i][j] == x