FunctionRacerProblemsRace

Snake Read

BeginnerGridsPython, JavaScript, TypeScript, Java, C++

Read grid the way a snake crawls: row 0 from left to right, row 1 from right to left, row 2 from left to right, and so on, changing direction on every row. Return all the numbers in that order as one flat list.

Example 1

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

Row 0 is read as 1, 2, 3; row 1 backwards as 6, 5, 4; row 2 forwards as 7, 8, 9.

Example 2

grid [[1,2],[3,4],[5,6],[7,8]]
returns [1,2,4,3,5,6,8,7]

Rows with an odd index (1 and 3) are read backwards.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Grids problems