Arrays wave pattern

my code is giving the right output , but its failing the testcases.

@Aug19LPPP0098 Consider test case:
2 6
1 2 3 4 5 6
7 8 9 10 11 12

Your Output:
1, 7, 8, 2, END

Dry run and check where your code goes wrong.