grid of positive integers. Walk through it like a snake: the first row left to right, the second right to left, the third left to right again, and so on down to the last row.
Along the way, write down every other number: record the first cell of the path, skip the second, record the third, and so on. The alternation carries over from one row to the next and is never reset.
Return the recorded numbers in the order you visited them.grid=[[4, 8, 15], [16, 23, 42]] → [4, 15, 23]
The full snake path is 4, 8, 15, then right to left 42, 23, 16. Taking every other cell from the first gives 4, 15, 23.
grid=[[7, 1], [9, 3], [5, 6]] → [7, 3, 5]
The path is 7, 1, 3, 9, 5, 6. Every other cell: 7, 3, 5.
grid=[[2, 4, 6, 8], [1, 3, 5, 7]] → [2, 6, 7, 3]
grid=[[4, 8, 15], [16, 23, 42]]
[4, 15, 23]
Run checks the first 3 tests in your browser. Submit checks all 70 tests on the server, hidden ones included.