Add count of substring equal to n - alphaIndex [ i ] [ j ]
rank = rank + ( n - alphaIndex [ i ] [ j ] ) ; } } } var str = [ ] ; for ( var i = 0 ; i < alphaIndex [ s [ 0 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] . length ; i ++ ) {