Pop the back element from the vp until the first value is same as val and difference between indices is less than K
while ( ! vp . empty ( ) && vp . back ( ) . first == val && ind - vp . back ( ) . second + 1 <= K ) vp . pop_back ( ) ; }