# CONVSTR - Editorial

can anybody tell me on which test case it is failing.

https://www.codechef.com/viewsolution/33502259

another variation

https://www.codechef.com/viewsolution/33500860

1 Like

https://www.codechef.com/viewsolution/33474395

Any testcase for which solution fails ?
Got 30/100.

Can’t figure out where my code gives WA for second subtask, could someone help?

Could someone figure out my mistake.
My Idea was to iterate from z to a find positions of the that char in both a and b if differ count increases.If a doesnt contain it return -1.
My solution link https://www.codechef.com/viewsolution/33489863

Can anyone tell me what si wrong with my code, all test case are passed

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
int dp[26];
while(t–)
{
memset(dp,-1,sizeof(dp));
int n;
cin>>n;
string s1,s2;
cin>>s1>>s2;
bool flag=0;
vector<pair<char,int> >v;
for (int j=0;j<n;j++)
dp[s1[j]-‘a’]=j;
for (int j=0;j<n;j++)
{
if (s1[j]!=s2[j])
{
if (s1[j]>s2[j])
{
if (dp[s2[j]-‘a’]!=-1)
{
v.push_back({s2[j],j});
}
else
{
flag=1;
break;
}
}
else
{
flag=1;
break;
}
}
}
if (flag==1)
{
cout<<"-1"<<endl;
continue;
}
else
{
int r=v.size();
vectorv1,result;
for (int j=0;j<r;)
{
vectorans;
char temp=v[j].first;
ans.push_back(dp[v[j].first-‘a’]);
while(j<r&&v[j].first==temp)
{
ans.push_back(v[j].second);
j++;
}
int e=ans.size();
v1.push_back(e);
for (int k=0;k<e;k++)
result.push_back(ans[k]);
}
int e=v1.size();
cout<<e<<endl;
int k=0;
for (int j=0;j<e;j++)
{
cout<<v1[j]<<" “;
int r=k+v1[j];
for (;k<r;k++)
cout<<result[k]<<” ";
cout<<endl;
}
}
}

}

rankings are updated

Your code fails on this test -
acebf
aabbe

1 Like

Try this test case:
3
5
defgb
bbebb
5
defgb
bbbeb
5
defgb
bbbfb

Your code outputs -1 for each task. But it is possible to covert the string.

1 Like

Anyone having doubt can take a look at my code and dry run against theirs to find the mistake. I have added comments for better readability. Solution.

2 Likes

explain it your code is messed up boi

you have to start with the largest character also code is very messed up and hard to understand at some places try to write clean and easy code it will be good also next time post the link of your submission instead of the code itself!! GOOD LUCK :D!!

1 Like

Sir, we have to view which solution here. I’m new here, is the main solution to be uploaded later?

Can anyone please tell about the mistake in my solution? I am sure that it will get TLE but it is getting WA too. Were Ais to be written in ascending order only?
https://www.codechef.com/viewsolution/33510740

hey @naman19vyas heres my code …
this is my code for subtask 1
where it went wrong man!!

omg I had correct solution, just had to loop from ‘z’ to ‘a’ instead of ‘a’ to ‘z’. Nice editorial, thanks a lot.

1 Like

I implemented the solution as Tester’s but don’t know after thinking of going from z to a, I traversed from a to z . . . damn . . . welcome back 3*

1 Like

plz give the link of the submission

shit happens

1 Like