Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
imteekay committed Jan 3, 2024
1 parent 604997c commit 40c4a06
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions coding_interviews/algoexpert/spiral-traverse/spiral-traverse.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/**
*
* Write a function that takes in an n x m two-dimensional array (that can be square-shaped when n == m)
* and returns a one-dimensional array of all the array's elements in spiral order.
* Spiral order starts at the top left corner of the two-dimensional array, goes to the right,
* and proceeds in a spiral pattern all the way until every element has been visited.
*
* Input:
* array = [
* [1, 2, 3, 4],
* [12, 13, 14, 5],
* [11, 16, 15, 6],
* [10, 9, 8, 7],
* ]
*
* Output:
* [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
*/

// Right: keep the row and increase the column
// Bottom: keep the column and increase the row
// Left: keep the row and decrease the column
Expand Down

0 comments on commit 40c4a06

Please sign in to comment.