Stores frequency of elements separated by distance K
var freq = new Map ( ) ; for ( j = i ; j < N ; j += K ) { if ( freq . has ( arr [ j ] ) ) freq . set ( arr [ j ] , freq . get ( arr [ j ] ) + 1 ) ; else freq . set ( arr [ j ] , 1 ) ; }