this solution is not passing one the test cases please help and comment the the new lines added or modified
Https://hack.codingblocks.com/app/contests/1282/966/problem
it passed a small test case
try going by the method bhaiya told
in the hint video
use custom sort
bool cmp(string a, string b){
if(a.size() <= b.size() && b.substr( 0 , a.size()) == a) return false;
if(b.size() <= a.size() and a.substr(0,b.size() ) == b) return true);
return a < b;
}
what will happen when returned true or false, how will the sort function determine if returned true or false does it have to sort in ascending order or descending
i understood the if conditions and return a<b
Hi @AyushKumar9032
Your previous code had a minor mistake. I have corrected and commented it.
Link : https://ide.codingblocks.com/s/223635
Hope it Helps.
Oh such a silly mistake I couldn’t figure out thanks!
I want understand this part too I have seen this custom sort at times what will happen if CMP function returns false and what will happen if return true I mean to say how will sort function get to know that is it to be sorted in ascending or descending a<bis easy to understand
it returns true if a should preceed b and false if we need to swap them.
If a<b if this condition is true it would sort in ascending order and if false then also ascending order so how come return false can give me initiution that how will it get sorted
what I am trying to say is it depends upon the operator used on that basis it sorts
If written a<b it will sort in ascending order because of the condition becomes true or false it doesn’t depend on that so how come return true or return false determine how to sort
How come are these 2 id’s active? Just reply from only 1 id. Why are you changing id’s.
I think my doubt is not clear to you a<b it
Sort function will sort according to the operator used although CMP returns true or false
So how will it determine that if return false how to sort
Okay I will not use first I had used android CB now using website on mobile sorry for trouble
in cmp function, the compiler itself sends two elements of the array each time. And let we write it as
int cmp(int a,int b);
Now if it returns true then, compiler places a before b. If it returns false, compiler swaps them;
So, if we want to sort in ascending order, we will return a<b; If we want to sort in descending order we return a>b;