Doubt in return statement

here in if condition he returned a<b and in below statement he returned a.length<b.length.So basically how the comparison is gonna take place, does this mean we already considered that a will be less than b, means I can’t understand how a and b are gonna be compared if we already returned a<b.

hello @aatmictiwari19

let say u pick 2 numbers of array. (say a and b ) note : b comes after a in array.

now in comparator u need to wrtie a logic on how how these two numbers should be there in sorted array.
so if u do return a < b that means u want (smaller elements comes first in array and then bigger elements that is why we have < operator in between a and b)

similarly if u want that bigger element comes first and then smaller element then in such case
u need to do return a> b (i,e i want biiger element comes first and then smaller element that is why > sign).

now try to understand the working of given(in video) comparator based on above logic

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.