in this ques we need to find max number . ND we will use comparator function for sorting.
nd return statement will be by appending one array element to another. so if we want max number ,we want number with max first digit to come first;
so return statement should be
return x+y<y+x
but tht is doing the opposite thing. can uh plz tell why
Doubt regarding comparator function
hello @dhruv.mahajan.mait
this will form smallest number becuase it will put bigger numbers in the end.
correct comparator should be
return x+y > y+x; // i.e put those number first that are forming big values
but when we see the comparator function it works on the basis if return value is 1 then it swaps the elements.
nd for descending order we did return x<y.
nd stld sort funciion it is just like bubble sort.
so if we want max number then from my understanding it should be
x+y<y+x
coz then it will swap these 2 elements nd then the no with bigger first digit will come up first
no this is for ascending order.
pls revisit the comparator related videos
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.