Read an LED Panel Matrix in Clockwise Spiral Order

Last updated: November 29, 2026

Quick Overview

A Surface Hub boot animation lights an LED panel in a clockwise spiral starting from the top left. Given the panel as a matrix of values, return the values in the order they would light up.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


A Surface Hub boot animation lights an LED panel in a clockwise spiral starting from the top left. Given the panel as a matrix of values, return the values in the order they would light up.

Spiral traversal is a long running Microsoft phone screen question. The interviewer wants clean boundary bookkeeping that handles single rows and single columns without duplicating elements.

What the Interviewer Expects
  • Track four shrinking boundaries: top, bottom, left, right
  • Walk right, down, left, up in order, shrinking after each side
  • Guard the bottom and left passes to avoid duplicates
  • Handle non-square, single row, and single column inputs
  • Run in O(rows * cols)
Key Topics to Cover
matrix
simulation
boundaries
traversal
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Generate an n x n matrix filled in spiral order.
  • How would you produce the counterclockwise order starting from another corner?
  • Return the kth element of the spiral without building the whole list.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: rectangular matrix, possibly empty.
  • Output: elements in clockwise spiral order from the top left.
  • Each element appears exactly once....
High-Level Design

Maintain the unvisited rectangle with top, bottom, left, right. Each loop iteration peels its outer ring:

  1. Left to right across top, then move top down.
  2. Top to bottom along right, ...

Submit Your Answer
Markdown supported