Given a string 's', we can perform the following operation:-
1) Choose an index 'i' greater than the index chosen in previous operation and rotate the suffix(left or right rotate) formed from i, any number of times.
What is the minimum number of operations required to make smallest possible lexicographical string from s?
Size of input:- length of string<=10^3
Example:-
1) s:- acab
Choose suffix from index 1 and right rotate the string "cab" 2 times to the right to obtain "aabc" which is the smallest possible lexicographical string.
So the minimum number of operations required is 1.
2) s:- cdax
First, choose suffix from index 0 and rotate the string "cdax" two times to the right to get "axcd".
Now choose suffix from index 1 and rotate the string "xcd" 1 time to the left to obtain "cdx". Final string is "acdx".
So minimum number of operations required is 2.
Note:- In a single operation you can perform any number of left or right rotations on a suffix.