Wrong answer despite correct test output

@krishnamanohar199 hey manohar next time please write some description of issue before posting the link otherwise the automated api will mark you as spam
now come with the solution issue
remove line 19 take simple input don’t found with any condition
shift line 22 to 24 as you’re incrementing the counter of while loop i++;
and remove n–;
in the inbuild sort function do emp+n
and before output line apply a check emp[k].second>=x

1 Like

Why was my logic wrong ?
Does conditional increment of the looping variable provide incorrect results?
Because test cases I passed have all seemed to work fine in the run option.

@krishnamanohar199 actually you apply some restriction while taking input due to this the actual functionality of the code is not working properly. and while sorting how you can use increment variable i
but the actual syntax of the sort function. (sort,sort+n,custom comparator).

1 Like

Oh okayy. So must I never take conditional input in the future??
I have used ‘i’ because, the previous loop had reached till n , the value of i = n.
So how can I not use ‘i’ instead of ‘n’ ?

@krishnamanohar199 hey krishna actually in only while loop the i reach to n but outside while loop it is still i=0 because you was declare i as globally. yes you don’t take conditional input.

1 Like

By globally, do you mean declaring outside the while loop? Because I haven’t declared it outside the main function. Also if you meant declaring outside the while loop,


The above code outputs the incremented value of ‘i’ and not the declared value of it.

@krishnamanohar199 hey krishna basically yeah you’re right but thing with sort function is is passed with reference actually the pair of emp is passed with reference so for eg if I want to sort a array I have to passed it like sort(arr,arr+n) here the first parameter of arr is passed with base reference address which is zero and the arr+n the last index of the array which specify the total size of array is it good habit to pass it with syntax to avoid any errror

1 Like

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.