Skip to content

Commit c0634c6

Browse files
committed
Mar 06
1 parent 962c5e2 commit c0634c6

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from itertools import product
2+
3+
4+
class Solution:
5+
def findMissingAndRepeatedValues(self, grid: list[list[int]]) -> list[int]:
6+
n = len(grid)
7+
total = 0
8+
duplicate = None
9+
seen = [False] * n**2
10+
11+
for i, j in product(range(n), range(n)):
12+
num = grid[i][j]
13+
if seen[num-1]:
14+
duplicate = num
15+
else:
16+
total += num
17+
seen[num-1] = True
18+
19+
expected = (n**2 * (n**2 + 1)) // 2
20+
return [duplicate, expected-total]
21+
22+
23+
def main():
24+
grid = [[1, 3],
25+
[2, 2]]
26+
assert Solution().findMissingAndRepeatedValues(grid) == [2, 4]
27+
28+
grid = [[9, 1, 7],
29+
[8, 9, 2],
30+
[3, 4, 6]]
31+
assert Solution().findMissingAndRepeatedValues(grid) == [9, 5]
32+
33+
34+
if __name__ == '__main__':
35+
main()

2025-03-March-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| March 03 | [2161. Partition Array According to Given Pivot](https://leetcode.com/problems/partition-array-according-to-given-pivot/) | Medium | Solved |
1010
| March 04 | [1780. Check if Number is a Sum of Powers of Three](https://leetcode.com/problems/check-if-number-is-a-sum-of-powers-of-three/) | Medium | Solved |
1111
| March 05 | [2579. Count Total Number of Colored Cells](https://leetcode.com/problems/count-total-number-of-colored-cells/) | Medium | Solved |
12-
| March 06 | []() | | |
12+
| March 06 | [2965. Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values/) | Easy | Solved |
1313
| March 07 | []() | | |
1414
| March 08 | []() | | |
1515
| March 09 | []() | | |
@@ -40,6 +40,6 @@
4040
## Summary
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
43-
| Easy | 2 | 2 | 0 |
43+
| Easy | 3 | 3 | 0 |
4444
| Medium | 3 | 1 | 3 |
4545
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)