cruzer12's blog

By cruzer12, history, 8 years ago, In English

What's wrong with this code?? Its giving me WA on test case 11.Can someone suggest corner cases for this problem.

include<bits/stdc++.h>

define ll long long

using namespace std;

int main() { ll t,n,i; // cin>>t;

// while(t--) // { cin>>n; char ch[n]; set s; cin>>ch;

    for(i=0;i<n;i++)
    {
       s.insert(ch[i]);
    }

    if(s.size()==1) 
    {
       cout<<"1"<<endl;
    }
    else
    {
       ll pokemons=s.size();     
       ll j=0,k=n-1;
       while(ch[j]==ch[j+1]) j++;
       while(ch[k]==ch[k-1]) k--;

       map<char,ll> m;
       ll count1=0,count2=0;
       for(i=j;i<=k;i++)
       {
         if(m.size()==pokemons) break;
         m[ch[i]]++;
         count1++;
       }
       m.clear();
       for(i=k;i>=j;i--)
       {
         if(m.size()==pokemons) break;
         m[ch[i]]++;
         count2++;
       }

       ll ans=min(count1,count2);
       cout<<ans<<endl;
       s.clear();
       m.clear();
    }  

// } return 0; }

Full text and comments »

  • Vote: I like it
  • -33
  • Vote: I do not like it