up
, right
, down
, and left
to their respective starting values.result
to store the spiral order.left
to right
and add elements to result
, then update up
boundary.
b. Traverse from up
to down
and add elements to result
, then update right
boundary.
c. Check if up
boundary is less than down
boundary, then traverse from right
to left
and add elements to result
, then update down
boundary.
d. Check if left
boundary is less than right
boundary, then traverse from down
to up
and add elements to result
, then update left
boundary.result
list.