Note - str [ i . . n ] is sorted in ascending order Find rightmost element 's index  that is less than str[i - 1]
let j = i - 1 ; while ( j + 1 <= n && str [ j + 1 ] . charCodeAt ( 0 ) <= str [ i - 1 ] . charCodeAt ( 0 ) ) { j ++ ; }