2965. Find Missing and Repeated Values Easy

@problem@discussion
#Array#Hash Table#Math#Matrix



1/**
2 * [2965] Find Missing and Repeated Values
3 *
4 * You are given a 0-indexed 2D integer matrix <font face="monospace">grid</font> of size n * n with values in the range [1, n^2]. Each integer appears exactly once except a which appears twice and b which is missing. The task is to find the repeating and missing numbers a and b.
5 * Return a 0-indexed integer array ans of size 2 where ans[0] equals to a and ans[1] equals to b.
6 *  
7 * <strong class="example">Example 1:
8 * 
9 * Input: grid = [[1,3],[2,2]]
10 * Output: [2,4]
11 * Explanation: Number 2 is repeated and number 4 is missing so the answer is [2,4].
12 * 
13 * <strong class="example">Example 2:
14 * 
15 * Input: grid = [[9,1,7],[8,9,2],[3,4,6]]
16 * Output: [9,5]
17 * Explanation: Number 9 is repeated and number 5 is missing so the answer is [9,5].
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	2 <= n == grid.length == grid[i].length <= 50
23 * 	1 <= grid[i][j] <= n * n
24 * 	For all x that 1 <= x <= n * n there is exactly one x that is not equal to any of the grid members.
25 * 	For all x that 1 <= x <= n * n there is exactly one x that is equal to exactly two of the grid members.
26 * 	For all x that 1 <= x <= n * n except two of them there is exatly one pair of i, j that 0 <= i, j <= n - 1 and grid[i][j] == x.
27 * 
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/find-missing-and-repeated-values/
32// discuss: https://leetcode.com/problems/find-missing-and-repeated-values/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37    pub fn find_missing_and_repeated_values(grid: Vec<Vec<i32>>) -> Vec<i32> {
38        vec![]
39    }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_2965() {
50    }
51}
52


Back
© 2025 bowen.ge All Rights Reserved.