Lexicographically minimum string rotation | Set 1 | This function return lexicographically minimum rotation of str ; Find length of given string ; Create an array of strings to store all rotations ; Create a concatenation of string with itself ; One by one store all rotations of str in array . A rotation is obtained by getting a substring of concat ; Sort all rotations ; Return the first rotation from the sorted array ; Driver Code
def minLexRotation ( str_ ) : NEW_LINE INDENT n = len ( str_ ) NEW_LINE arr = [ 0 ] * n NEW_LINE concat = str_ + str_ NEW_LINE for i in range ( n ) : NEW_LINE INDENT arr [ i ] = concat [ i : n + i ] NEW_LINE DEDENT arr . sort ( ) NEW_LINE return arr [ 0 ] NEW_LINE DEDENT print ( minLexRotation ( " GEEKSFORGEEKS " ) ) NEW_LINE print ( minLexRotation ( " GEEKSQUIZ " ) ) NEW_LINE print ( minLexRotation ( " BCABDADAB " ) ) NEW_LINE