i am unable to deal with this case
Eg bat, batman are 2 strings and the string bat is present as a prefix in Batman - then sorted order should have - Batman, bat.
please give me some hint.
Doubt in string sort
i am able to write code for sorting array of string length wise
and also for sorting array of string lexicographically but unable to merge them as required in this question
so, help me to fix it.
hey @shubham.mehla2000, use the below logic
bool mycompare(string a, string b)
{
if(a.find(b)==0|| b.find(a)==0)
{
return a.length() > b.length();
}
return a<b;
}
a is sub string of b or b is sub string of a
1 Like