CONVSTR - Editorial

BRO,can u please little comment yout code…

Your code fails on
abcde , aabaa
Check your output

1 Like

Video Editorial of Convert String.
(Tester Approach)
:slightly_smiling_face::slightly_smiling_face:

3 Likes

https://www.codechef.com/viewsolution/33508813
Why only partially accepted?

On this case -
abcde
aabbe
smallest number of operations needed is 2
your code outputs 3

2 Likes

i think this case will give wrong answer.
4
aabc
aaab
check it out.

2 Likes

https://www.codechef.com/viewsolution/33482147
Can someone help me to figure out why I am getting WA in 1st subtask while getting AC in 2nd?

Thanks man, got it.

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