Comments

I got it. I was wrongly updating my mex value of left array. Thanks :)

I had trouble solving B even after getting the correct logic.

I thought the array can be divided in 2 parts always if there was an answer. I calculated the MEX of the whole array. Now I divided the array in two parts of size i(left array) and n-i(right array), where 1<i<n . I updated the MEX of the left and right array in each loop and if they were equal printed the indices. Here is my code, can someone help :

#include <bits/stdc++.h>
using namespace std;
using ll=long long;

void solve(int tt)
{
    ll n,x;

    cin>>n;
    ll a[n];

    map<ll,ll>mp;

    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }

    ll mex=n;
    for(ll i=0;i<n;i++)
    {
        if(mp.find(i)==mp.end())
        {
            mex=i;
            break;
        }
    }

    ll mex2=0;
    for(ll i=0;i<n;i++)
    {
        if(a[i]==mex2)
        {
            mex2++;
        }

        mp[a[i]]--;
        if(mp[a[i]]==0 && a[i]<mex)
        {
            mex=a[i];
        }

        if(mex==mex2)
        {
            cout<<2<<endl;
            cout<<"1 "<<i+1<<endl;
            cout<<i+2<<" "<<n<<endl;
            return;
        }
    }
    cout<<-1<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int T=1;
    cin >> T;
    for(int tt=1; tt<=T; tt++)
    {
        solve(tt);
    }
    return 0;
}

Got it. Thanks !

I was getting wrong answer on test2 for D.

My approach: Obtain a new string by adding the substrings from index (0 to l-1) and (r to last-1). Now check if str is a substring of this new string.

Here is my code , can you help where i am wrong...

My Code