Find Integer Pair in Array with K elements Between

You are given an array of integers that contains some duplicates and an integer K as arguments. Return the value of the first duplicated integer that has K elements between the first instance and the second instance.

Requirements

  • Must return an integer

Example #1

solve([0, 0, 3, 1, 5, 7, 4, 8, 3, 1, 5], 5)
> 3

There are 5 elements (integers 1, 5, 7, 4, 8), between the first instance of 3 and the second instance of 3.

Example #2

solve([0, 0, 1, 5, 7, 4, 5, 8, 3, 1, 8, 3], 2)
> 5

There are 2 elements (integers 7, 4), between the first instance of 5 and the second instance of 5.