The code is working fine with almost all the test cases i tried with. But it is not able to pass the 2nd test case

Hello @pranav_sharma,

You are not checking for subsets. You are only comparing the first element.
Example:
4
bat
apple
batman
batt
Expected Output:
apple
batman
bat
batt

You can refer to the following code:
1.
bool mycompare(string a,string b)
{
string r=a.substr(0,b.length());
string s=b.substr(0,a.length());
if(r==b||s==a)
{
return a.length()>b.length();
}
else
{
return a<b;
}
}
2.
bool mycompare(string a,string b){
int i=0;
while(a[i]==b[i]) i++;
if(a[i]==’\0’) return false;
else if(b[i]==’\0’) return true;
return a < b;
}

Hope, this would help.
Give a like, if you are satisfied.