Hey please tell the error

hello @adarshsingh2k

u havent considered this case in ur code

how to do that now in my code

check whether one string is prefix of other string or not.
if it is then order them on basis of there length otherwise order them lexicographically.

and for that u can use loop.

#include<bits/stdc++.h> using namespace std; bool compare(string s, string s1){ if(s[0]==s1[0]) return s.length()>s1.length(); // descending order. else return s<s1; // ascending order. } int main() { int n; string s[1000]; cin>>n; for(int i=0;i<n;i++){ cin>>s[i]; } sort(s,s+n,compare); for(int i=0;i<n;i++){ cout<<s[i]<<endl; } return 0; }

whats wrong in this https://ide.codingblocks.com/s/335079

your logic for checking prefix is not correct.
use loop and iterate through the given strings to check whether one is prefix of other or not

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.