The test case 1 seems to be failing even though I tried the output with different rows and columns different as well.
Test case 1 failing
input:
3 4
1 2 3 4
1 2 3 4
1 2 3 4
Correct output:
1, 2, 3, 4, 4, 4, 3, 2, 1, 1, 2, 3, END
your output:
1, 2, 3, 4, 4, 4, 3, 2, 1, 1, 2, 3, 2, END
2 is being printed 4 times.