Not sure what's wrong

Hello Sir!
I wrote my code for this problem, and submitted it on Spoj
where I am getting an AC. However, when I submit it here,
even after modifying for the k == 0 case, i am getting WA in 4 test cases. I think my approach is correct, can you please help me and tell me what’s wrong?

Code: https://ideone.com/mbaZjF

@kunalarora123 at line 22 where you are checking if arr[j]==val you should check if val exist inside that arr.

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.