Store suffixes and their indexes in an array of structures . The structure is needed to sort the suffixes alphabatically and maintain their old indexes while sorting
for i in range ( n ) : NEW_LINE INDENT suffixes [ i ] . index = i NEW_LINE suffixes [ i ] . rank [ 0 ] = ord ( txt [ i ] ) - ord ( ' a ' ) NEW_LINE suffixes [ i ] . rank [ 1 ] = ( ord ( txt [ i + 1 ] ) - ord ( ' a ' ) ) if ( ( i + 1 ) < n ) else - 1 NEW_LINE DEDENT