How WA in CONVSTR

can anybody tell me where I am getting wrong .

solution link:
https://www.codechef.com/viewsolution/33521609

#include<bits/stdc++.h>
using namespace  std;
 
typedef  long  long int ll;
typedef  vector<int> vi;
vi use[26];
vi forb[26];
void solve()
{
    int n; cin>>n;
    string a,b; cin>>a>>b;
    vi va(26,0),vb(26,0);
    for(int i=0;i<n;i++)
    {
        va[a[i]-'a']=1;
        vb[b[i]-'a']=1;
    }
    set<int> s;
    for(int i=0;i<n;i++)
    {
        if(b[i]!=a[i])
        {
            s.insert(b[i]-'a');
        }
        if(a[i]<b[i]){cout<<-1<<endl;return;}
    }
    int f=1;
    for(int i=0;i<26;i++)
    {
        if(vb[i]==1 and va[i]==0)
            {f=0;break;}
    }
    if(!f){cout<<-1<<endl;return;}
    for(int i=0;i<n;i++)
    {
        use[a[i]-'a'].push_back(i);
        forb[b[i]-'a'].push_back(i);
    }
    vi ans;
    int cnt=0;
    cout<<s.size()<<endl;
    for(auto i:s)
    {
            int temp=use[i][0];
            int pri=1;
            for(int j=0;j<forb[i].size();j++)
            {
                if(forb[i][j]==temp){pri=0;cout<<forb[i].size()<<" ";}
            }
            if(pri){cout<<forb[i].size()+1<<" ";cout<<temp<<" ";}
            for(int j=0;j<forb[i].size();j++)cout<<forb[i][j]<<" ";cout<<endl;

    }
    for(int i=0;i<26;i++)
    {
        use[i].clear();
        forb[i].clear();
    }
}

int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

int t; cin>>t; while(t--) 
solve();
}

Sorry but i don’t do C++14, so can’t help you there mate :cry: :flushed:

1 Like

we have to take distinct letters from B array and in increasing order of that letters position we have to add in A right ?