what we have to do when n is zero or negative
do we need to print anything or return from there?
Related to negative test cases
Hello @mihir_4116 no n cant be negative in this:
and if n is zero means aapke array hi empty h then you will not continue with the logic because if array is empty then you will compare on which elements.
though you will not find any such test case.
#include
#include
#include
#include
using namespace std;
bool comparator(string a,string b){
if(b.size()<=a.size() && a.substr(0,b.size())==b){
return true;
}else if(a.size()<=b.size() && b.substr(0,a.size())==a){
return true;
}else{
return a<b;
}
}
int main() {
int n;
cin>>n;
vector v(n);
if(n==0){
return 0;
}else{
for(int i=0;i<n;i++){
string s;
cin>>s;
v.push_back(s);
}
sort(v.begin(),v.end(),comparator);
for(auto x:v)cout<<x<<endl;
}
}
its showing wrong answer. can you show me where i did wrong
how to share code from coding blocks ide
go the link then paste your code and in that under file section you will see the save option after saving you have to share the link.
got it thanks
is there any whatsgroup that we have to join?
i enrolled in 1st april online premium batch