Why my only 2 testcase is passing

Your code is giving wrong output for testcase:
4 3
1 1 2 2