Skip to main content
Back to problems
Leetcode
Medium
Matrices
Arrays
Simulation
Zigzag Grid Traversal With Skip

Traverse a grid in a zigzag row order while skipping cells at a fixed interval.

Acceptance 0%
Problem Statement

Zigzag Grid Traversal With Skip

You are given a 2D grid with m rows and n columns, and a positive integer skip.

Traverse the grid row by row in a zigzag pattern:

  • row 0 is read left to right,
  • row 1 is read right to left,
  • row 2 is read left to right,
  • and so on.

As you visit cells in this zigzag order, keep only the cells that are not skipped. A cell is skipped according to the given skipping rule for the problem, and you must return the values of the cells that remain after applying the rule.

Your task is to produce the traversal result in order.

Input Format

  • A 2D integer grid grid of size m x n.
  • An integer skip describing the skip interval/rule.

Output Format

  • Return an array of integers containing the values collected during the zigzag traversal after applying the skip rule.

Constraints

  • 1 <= m, n
  • grid contains integers
  • skip is a positive integer
  • The grid size is small enough for straightforward traversal in an interview setting

Hints

  • First focus on generating the zigzag order correctly.
  • Use a counter while traversing to decide whether the current cell should be kept or skipped.
  • Be careful with row direction changes on alternating rows.

Input Format

  • grid: integer matrix
  • skip: positive integer

Output Format

  • Integer array representing the collected values in traversal order

Constraints

  • Traverse all cells in zigzag row order.
  • Apply the skip rule consistently while visiting cells.
  • Return values in the exact order they are collected.
Examples
Sample cases returned by the problem API.

Example 1

Input

grid = [[1,2,3],[4,5,6],[7,8,9]], skip = 3

Output

[1,2,4,5,7,8]

Explanation

Zigzag order is [1,2,3,6,5,4,7,8,9]. Skipping every 3rd visited cell removes 3, 6, and 9, leaving [1,2,4,5,7,8].

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.