why my code is giving wa

Cos the logic is not right. You need to calc the minimum number of steps (it doesn’t matter who’s greater than whom). If k is less than this, it’s NO. Else, check if the parity of min steps and K is same (as you can go ahead of the destination and return back in even number of steps). If it’s not, it’s NO. For all other cases, it’s YES

also can u tell me which test case my code is giving wa

Because, it is wrong!!! your code is drawing wrong comparisons in the calculated values as per the problem.

0 0 0 1 5

Answer is YES, you’re printing NO

but dude it will take only 1 step to reach 0 1 it say **exactly k** step so ans will no

Read the question again, it doesn’t say you have to reach that square in minimum number of steps. Even the sample tests covers a similar case.

Check test case 3 in the example problems. 1,1 to 1,0 can be reached in EXACTLY THREE steps (while just one is sufficient).

Accordingly, in your code: ans-k%2 == 0 would fix it. Not just ans==k (as explained above)

Ps: else without if???