Stores frequency of elements separated by distance K
Map < Integer , Integer > freq = new HashMap < > ( ) ; for ( int j = i ; j < N ; j += K ) freq . put ( arr [ j ] , freq . getOrDefault ( arr [ j ] , 0 ) + 1 ) ;