3417. Zigzag Grid Traversal With Skip Easy

@problem@discussion
#Array#Matrix#Simulation



1/**
2 * [3417] Zigzag Grid Traversal With Skip
3 *
4 * You are given an m x n 2D array grid of positive integers.
5 * Your task is to traverse grid in a zigzag pattern while skipping every alternate cell.
6 * Zigzag pattern traversal is defined as following the below actions:
7 * 
8 * 	Start at the top-left cell (0, 0).
9 * 	Move right within a row until the end of the row is reached.
10 * 	Drop down to the next row, then traverse left until the beginning of the row is reached.
11 * 	Continue alternating between right and left traversal until every row has been traversed.
12 * 
13 * Note that you must skip every alternate cell during the traversal.
14 * Return an array of integers result containing, in order, the value of the cells visited during the zigzag traversal with skips.
15 *  
16 * <strong class="example">Example 1:
17 * <div class="example-block">
18 * Input: <span class="example-io">grid = [[1,2],[3,4]]</span>
19 * Output: <span class="example-io">[1,4]</span>
20 * Explanation:
21 * <img alt="" src="https://assets.leetcode.com/uploads/2024/11/23/4012_example0.png" style="width: 200px; height: 200px;" />
22 * </div>
23 * <strong class="example">Example 2:
24 * <div class="example-block">
25 * Input: <span class="example-io">grid = [[2,1],[2,1],[2,1]]</span>
26 * Output: <span class="example-io">[2,1,2]</span>
27 * Explanation:
28 * <img alt="" src="https://assets.leetcode.com/uploads/2024/11/23/4012_example1.png" style="width: 200px; height: 240px;" />
29 * </div>
30 * <strong class="example">Example 3:
31 * <div class="example-block">
32 * Input: <span class="example-io">grid = [[1,2,3],[4,5,6],[7,8,9]]</span>
33 * Output: <span class="example-io">[1,3,5,7,9]</span>
34 * Explanation:
35 * <img alt="" src="https://assets.leetcode.com/uploads/2024/11/23/4012_example2.png" style="width: 260px; height: 250px;" />
36 * </div>
37 *  
38 * Constraints:
39 * 
40 * 	2 <= n == grid.length <= 50
41 * 	2 <= m == grid[i].length <= 50
42 * 	1 <= grid[i][j] <= 2500
43 * 
44 */
45pub struct Solution {}
46
47// problem: https://leetcode.com/problems/zigzag-grid-traversal-with-skip/
48// discuss: https://leetcode.com/problems/zigzag-grid-traversal-with-skip/discuss/?currentPage=1&orderBy=most_votes&query=
49
50// submission codes start here
51
52impl Solution {
53    pub fn zigzag_traversal(grid: Vec<Vec<i32>>) -> Vec<i32> {
54        vec![]
55    }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63
64    #[test]
65    fn test_3417() {
66    }
67}
68


Back
© 2025 bowen.ge All Rights Reserved.