Introduction

Hello, Go programmer! Are you ready to embark on an intriguing coding journey? In this lesson, we're going to explore special traversals of matrices in Go. Matrices are rectangular 2D arrays, where each inner array maintains the same size. We'll navigate a matrix by zigzagging through columns, climbing up and down. Sound exciting? Buckle up, then, and get ready!

Task Statement

Here's the task: You've been given a 2D slice consisting of individual cells, each holding a unique integer value. Your goal is to create a function that will traverse this matrix, starting at the bottom-right cell. From there, you'll travel up to the top of the same column, then move left to the next column, and continue downward from the top of this new column. After reaching the bottom of the column, you'll again move left and start moving upward. This unique traversal pattern will be performed until all the cells have been visited.

Consider this small 3x4 matrix as an example:

With the described traversal pattern, your function should return this list: [12, 8, 4, 3, 7, 11, 10, 6, 2, 1, 5, 9].

Solution Building: Step 1

The first step toward a solution is understanding the dimensions of the matrix with which we're working. We can do this using Go's built-in functions to determine the length of slices. Let's set up our function and identify the matrix size:

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal