Skip to content

Commit 62d30d8

Browse files
committed
add daily 2017. Grid Game
1 parent 8f4a030 commit 62d30d8

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ go test ./easy/0001_two_sum
4444
| [1368](https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid/?envType=daily-question&envId=2025-01-18) | [Minimum Cost to Make at Least One Valid Path in a Grid](/hard/1368_minimum_cost_to_make_at_least_one_valid_path_in_a_grid) | Hard | _`Breadth First Search`_ _`Graph`_ `Heap(Priority Queue)` _`Matrix`_ _`Shortest Path`_ _`Array`_ |
4545
| [407](https://leetcode.com/problems/trapping-rain-water-ii/?envType=daily-question&envId=2025-01-19) | [Trapping Rain Water II](/hard/1368_minimum_cost_to_make_at_least_one_valid_path_in_a_grid) | Hard | _`Breadth First Search`_ _`Graph`_ `Heap(Priority Queue)` _`Matrix`_ _`Shortest Path`_ _`Array`_ |
4646
| [2661](https://leetcode.com/problems/first-completely-painted-row-or-column/description/?envType=daily-question&envId=2025-01-20) | [First Completely Painter Row or Column](/medium/2661_first_completely_painted_row_or_column) | medium | _`Matrix`_ _`HashTable`_ _`Array`_ |
47+
| [2017](https://leetcode.com/problems/grid-game/) | [Grid Game](/medium/2017_grid_game) | medium | _`Matrix`_ _`Prefix Sum`_ |
4748

4849
## License 🪪
4950

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package grid_game
2+
3+
import "math"
4+
5+
func gridGame(grid [][]int) int {
6+
firstRowSum := 0
7+
for _, value := range grid[0] {
8+
firstRowSum += value
9+
}
10+
11+
secondRowSum := 0
12+
minimumSum := math.MaxInt
13+
14+
for turnIndex := 0; turnIndex < len(grid[0]); turnIndex++ {
15+
firstRowSum -= grid[0][turnIndex]
16+
minimumSum = min(minimumSum, max(firstRowSum, secondRowSum))
17+
secondRowSum += grid[1][turnIndex]
18+
}
19+
20+
return minimumSum
21+
}
22+
23+
func min(a, b int) int {
24+
if a < b {
25+
return a
26+
}
27+
return b
28+
}
29+
30+
func max(a, b int) int {
31+
if a > b {
32+
return a
33+
}
34+
return b
35+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package grid_game
2+
3+
import "testing"
4+
5+

0 commit comments

Comments
 (0)