To find the distance between any two occurences
for ( int i = 0 ; i < indices [ t ] . Count ; i ++ ) { gap = Math . Max ( gap , indices [ t ] [ i ] - start ) ; start = indices [ t ] [ i ] ; } if ( answer [ gap ] == - 1 ) answer [ gap ] = t ; }