Go in Zig Zag
EasyP3Coding
Return the elements of an N x M matrix in snake order as one array: the first row from right to left, the second row from left to right, the third row from right to left again, and so on.
Example 1
- Input
- matrix = [[1,2,3,4],[5,6,7,8],[4,5,7,2]]
- Output
- [4,3,2,1,5,6,7,8,2,7,5,4]
Example 2
- Input
- matrix = [[1,2],[3,4]]
- Output
- [2,1,3,4]
Example 3
- Input
- matrix = [[5]]
- Output
- [5]
Constraints
- 1 <= N, M <= 100
- -10^9 <= matrix[i][j] <= 10^9
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.