DIAGONAL TRAVERSAL PROBLEM

IF A 2D ARRAY OF SIZE 4 4 IS THERE
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
WHAT WILL BE THE OUTPUT?

hi @Mayankrocks
its expected o/p will be 1 2 5 9 6 3 4 7 10 13 14 11 8 12 15 16
refer this for better understanding–>

will this problem work on;y when no. of rows and no. of columns are equal?

It will work for unequal row, col also…

if we have 4 rows and 3 coulmns
1 2 3
4 5 6
7 8 9
10 11 12
what will be the o/p?

1 2 4 7 5 3 6 8 10 11 9 12

ok got it
send feedback link

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.