Insert all positions of every character in the given string .
var pos = Array . from ( Array ( MAX ) , ( ) => Array ( ) ) ; var n = str . length ; for ( var i = 0 ; i < n ; i ++ ) pos [ str [ i ] . charCodeAt ( 0 ) ] . push ( i + 1 ) ;