Back to problems Sign in to unlock
Leetcode
Medium
Arrays
Math
Hash Maps
Amazon
Microsoft
Find Missing And Repeated Values
Find the one value that appears twice and the one value that is missing from an grid containing numbers from $1n^2$.
Acceptance 0%
Problem Statement
Find Missing and Repeated Values
You are given an matrix containing integers from $1n^2$.
Exactly one number appears twice, and exactly one number in the range $1n^2$ does not appear at all.
Return the repeated value and the missing value.
Notes
- The matrix contains cells.
- Every value should be in the range $1n^2$.
- There is guaranteed to be exactly one repeated value and exactly one missing value.
Input Format
- A 2D integer array
gridof size . - Each cell contains an integer in the range .
- One value appears twice, one value is absent.
Output Format
Return an array of two integers [repeated, missing].
Constraints
- (typical interview-scale formulation)
- Values are in
- Exactly one value is repeated and exactly one value is missing
Examples
Sample cases returned by the problem API.
Example 1
Input
grid = [[1,3],[2,2]]
Output
[2,4]
Explanation
The values should be 1, 2, 3, 4. The number 2 appears twice, and 4 is missing.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.