Spiral Map (Arrays & Lists)

Read an r × c grid of integers and print its values in clockwise spiral order, starting top-left, on one line.

Input: r c, then r lines of c integers.

Output: The spiral, space-separated.

Difficulty: Hard. Write your answer in the browser editor, run the examples, then submit it against hidden tests. Python and JavaScript are free; other languages are part of licode Club.

Hint

  • Keep four bounds (top, bottom, left, right) and shrink them after each side.

More Arrays & Lists practice