Practice Zigzag Grid Traversal With Skip
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Traverse grid in row order, moving left to right across the first row, right to left across the second, and alternating direction thereafter. Starting with the first cell, keep every other visited cell and skip the cells between them, continuing the alternation across row boundaries. Return the kept values.
Source: Zigzag Grid Traversal With Skip on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
grid = [[1,2],[3,4]]
Output
[1,4]
# Example 2
Input
grid = [[2,1],[2,1],[2,1]]
Output
[2,1,2]
# Example 3
Input
grid = [[1,2,3],[4,5,6],[7,8,9]]
Output
[1,3,5,7,9]
Constraints
2 <= n == grid.length <= 50
2 <= m == grid[i].length <= 50
1 <= grid[i][j] <= 2500
Related LeetCode Problems
Practice more problems similar to Zigzag Grid Traversal With Skip.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.