To find the distance between any two occurences
for ( let i = 0 ; i < indices [ itr ] . length ; i ++ ) { gap = Math . max ( gap , indices [ itr ] [ i ] - start ) ; start = indices [ itr ] [ i ] ; } if ( answer [ gap ] == - 1 ) answer [ gap ] = itr ; }