array to store count of smaller characters on the right side of that index
var ans = Array ( n ) ; for ( var i = n - 1 ; i >= 0 ; i -- ) { arr [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ;