Pre - calculate prefix array
let prefix = new Array ( N ) ; for ( let i = 0 ; i < 26 ; i ++ ) { prefix [ i ] = new Array ( 26 ) ; for ( let j = 0 ; j < 26 ; j ++ ) { prefix [ i ] [ j ] = 0 ; } } preCalculate ( s , prefix ) ; let queries = [ [ 1 , 4 ] , [ 3 , 4 ] ] ; let q = queries . length ;