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

Minimal Rotation -CSES String Problem

Revision en3, by Archade_123, 2023-09-11 05:10:25

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);
  • }
Tags string, cses

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English Archade_123 2023-09-11 05:10:25 48
en2 English Archade_123 2023-09-11 05:09:33 12 (published)
en1 English Archade_123 2023-09-11 05:08:57 719 Initial revision (saved to drafts)