| 1 | class Solution { |
| 2 | public long gridGame(int[][] grid) { |
| 3 | //find top sum |
| 4 | long topSum=0; |
| 5 | int n = grid[0].length; |
| 6 | for(int i=0;i<n;i++){ |
| 7 | topSum += grid[0][i]; |
| 8 | } |
| 9 | long bottomSum=0; |
| 10 | long ans=Long.MAX_VALUE; |
| 11 | for(int p=0;p<n;p++){ |
| 12 | //sub top val |
| 13 | topSum -= grid[0][p]; |
| 14 | //find ans |
| 15 | ans = Math.min(ans, Math.max(topSum,bottomSum)); |
| 16 | //add bottom val |
| 17 | bottomSum += grid[1][p]; |
| 18 | } |
| 19 | // 2n |
| 20 | // constant |
| 21 | return ans; |
| 22 | } |
| 23 | } |
nothing calls this directly
no outgoing calls
no test coverage detected