Tap here to switch tabs
Problem
Submissions

Problem: Zigzag Grid Traversal With Skip

Zigzag Grid Traversal With Skip traverses a matrix row by row, reversing direction on each row, and returns the values from every other visited cell, starting with the first.

Statement

You are given a 22D integer matrix grid of size n×mn \times m.

Traverse the grid in a zigzag order according to the following process:

  • Start at the top left cell of the grid.

  • Move from left to right on even indexed rows (starting with row 00).

  • Move from right to left on odd indexed rows.

  • Alternate directions for each consecutive row until all elements have been traversed.

  • Include every alternating element in the result, starting by including the very first cell visited.

Return an array of integers containing the collected values in the order they were visited.

Constraints:

  • 2≤n==2 \leq n == grid.length ≤50\leq 50

  • 2≤m==2 \leq m == grid[i].length ≤50\leq 50

  • 1≤1 \leq grid[i][j] ≤2500\leq 2500

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Zigzag Grid Traversal With Skip

Zigzag Grid Traversal With Skip traverses a matrix row by row, reversing direction on each row, and returns the values from every other visited cell, starting with the first.

Statement

You are given a 22D integer matrix grid of size n×mn \times m.

Traverse the grid in a zigzag order according to the following process:

  • Start at the top left cell of the grid.

  • Move from left to right on even indexed rows (starting with row 00).

  • Move from right to left on odd indexed rows.

  • Alternate directions for each consecutive row until all elements have been traversed.

  • Include every alternating element in the result, starting by including the very first cell visited.

Return an array of integers containing the collected values in the order they were visited.

Constraints:

  • 2≤n==2 \leq n == grid.length ≤50\leq 50

  • 2≤m==2 \leq m == grid[i].length ≤50\leq 50

  • 1≤1 \leq grid[i][j] ≤2500\leq 2500