Skip to content

Commit f75483e

Browse files
committed
Jan 20
1 parent bb98c16 commit f75483e

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from itertools import accumulate
2+
from typing import List
3+
4+
5+
class Solution:
6+
def gridGame(self, grid: List[List[int]]) -> int:
7+
row1 = list(accumulate(grid[0][::-1]))[::-1] + [0] # postfix sums
8+
row2 = [0] + list(accumulate(grid[1])) # prefix sums
9+
10+
res = float('inf')
11+
for i in range(len(grid[0])):
12+
# find col where robot 1 changes rows
13+
top_points = row1[i+1]
14+
bottom_points = row2[i]
15+
# robot1 wants to minimize what robot2 can maximize
16+
res = min(res, max(top_points, bottom_points))
17+
return res
18+
19+
20+
def main():
21+
grid = [[2, 5, 4],
22+
[1, 5, 1]]
23+
assert Solution().gridGame(grid) == 4
24+
25+
grid = [[3, 3, 1],
26+
[8, 5, 2]]
27+
assert Solution().gridGame(grid) == 4
28+
29+
grid = [[1, 3, 1, 15],
30+
[1, 3, 3, 1]]
31+
assert Solution().gridGame(grid) == 7
32+
33+
34+
if __name__ == '__main__':
35+
main()

2025-01-January-LeetCoding-Challenge/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
| January 17 | [2683. Neighboring Bitwise XOR](https://leetcode.com/problems/neighboring-bitwise-xor/) | Medium | Solved |
2323
| January 18 | [1368. Minimum Cost to Make at Least One Valid Path in a Grid](https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid/) | Hard | Unsolved |
2424
| January 19 | [407. Trapping Rain Water II](https://leetcode.com/problems/trapping-rain-water-ii/) | Hard | Unsolved |
25-
| January 20 | [2661. First Completely Painted Row or Column](https://leetcode.com/problems/first-completely-painted-row-or-column/) | | |
26-
| January 21 | []() | | |
25+
| January 20 | [2661. First Completely Painted Row or Column](https://leetcode.com/problems/first-completely-painted-row-or-column/) | Medium | Solved |
26+
| January 21 | [2017. Grid Game](https://leetcode.com/problems/grid-game/) | Medium | Solved |
2727
| January 22 | []() | | |
2828
| January 23 | []() | | |
2929
| January 24 | []() | | |
@@ -40,5 +40,5 @@
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
4242
| Easy | 4 | 4 | 0 |
43-
| Medium | 13 | 11 | 2 |
43+
| Medium | 14 | 12 | 2 |
4444
| Hard | 2 | 0 | 2 |

0 commit comments

Comments
 (0)