Consider all remaining substrings . We consider every substring ending with index i .
for ( int i = k ; i < s . length ( ) ; i ++ ) { currStr = currStr . substr ( 1 , k ) + s [ i ] ; if ( lexMax < currStr ) lexMax = currStr ; if ( lexMin > currStr ) lexMin = currStr ; }