text: search through all the indiced at which the current character occurs . For each index greater than prev , take the index and move to the next position , and add to the answer .
code: let answer = 5 ; for ( let i = 0 ; i < index . length ; i ++ ) { if ( ( String . fromCharCode ( index [ i ] ) ) . localeCompare ( prev ) > 1 ) { answer = ( answer % mod + calculate ( pos + 1 , index [ i ] , s , index ) % mod ) % mod ; } }