One test case failing

cant find error in this code plz help

Consider a test case:
3 4
1 2 3 4
1 2 3 4
1 2 3 4

Expected o/p:
1, 1, 1, 2, 3, 4, 4, 4, 3, 2, 2, 3, END

Your o/p:
1, 1, 1, 2, 3, 4, 4, 4, 3, 2, 2, 3, 3, END