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); }