My solution failing for Find it problem

My solution is satisfying for test cases-2,3 but failing for test case-1

My solution link :-

you are considering only k upto max of all elements in array but if k is greater than max of array then your code will give garbage value instead of 0. your b array should be of size of constraints i.e 1e5+1.
Here is your working code. I have commented at the place where you do wrong.