i tries it for atleast 1.5 hour but ended getting no idea
please give me some hint to solve this question!!
Doubt in spiral print anticlockwise
Hello @shubham.mehla2000,
Observe the following figure:

Suppose:
k - starting row index
m - ending row index
l - starting column index
n - ending column index
i - iterator
count- to record the no. of elements that have been traversed.
t- total number of elements in the matrix.
Algo:
Repeat till k < m && l < n:
- Check if count == t, then break.
- print the right column for i=k to m //first row
- increment l as you wonβt traverse that column again.
- Check if count == t, then break.
- print the lower row for i=l to n //last row
- decrement m
- Check if count == t, then break.
- print left column for i=m to k //last column
- decrement n
- Check if count == t, then break.
- print upper row for i=n to l //first row
- increment l
Hope, this would help.
Give a like, if you are satisfied.
1 Like