Please read the new rule regarding the restriction on the use of AI tools. ×

Archade_123's blog

By Archade_123, history, 13 months ago, In English

The code is working for all testcases except bbaabbabaa can you please suggest where is the mistake. - Input-:bbaabbabaa - - Correct Output -: aabbaabbab - Code Output-:aabbabaabb

  • void solve(){
  • string str;
  • cin>>str;
  • str+=str;
  • int n = str.size();
  • int i = 0;
  • int ans = 0;
  • while (i < n/2)
  • {
  • ans = i;
  • int k = i, j = i + 1;
  • while (j < n && s[j] >= s[k])
  • {
  • if (str[j] == str[k])
  • k++;
  • if (str[j] > str[k] )
  • k = i;
  • j++;
  • }
  • while(i <= k)
  • i += j — k;
  • }
  • cout<<s.substr(ans,n/2);
  • }
  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?