A multiplayer canvas game has a grid where grid[r][c] is the number of stars in cell (r, c). Two players' cursors start in the top row: one in the top-left cell and one in the top-right cell. On each turn both cursors move down one row, each to the column on its left, the same column, or the column on its right, staying inside the grid.
Every cell a cursor visits gives its stars. If both cursors are in the same cell, its stars count only once. Write collectStars(grid) that returns the most stars the two players can collect together by the time they reach the bottom row.
Input: grid = [[1,0,1],[0,5,0]] Output: 7
The top corners give 1 + 1. In row 1, one cursor takes the 5; the other can't add more.
Input: grid = [[2,3],[4,1]] Output: 10
2 + 3 on top, then one cursor takes 4 and the other takes 1.
1 <= rows <= 501 <= cols <= 200 <= grid[r][c] <= 100Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #508 Two Cursors Collecting Stars. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.