K-th Duplicate Element in an Array

Problem Given an array, find the k-th element that becomes a duplicate — the k-th distinct value (in scan order) to reach a second occurrence.

Input / Output

  • Input: integer array, integer k.
  • Output: the k-th value to hit its second occurrence, or a sentinel if fewer than k such values exist.

Constraints

  • 1 ≤ n ≤ 10^5.
  • Ordering is by when each value first reaches count 2, not by the value itself.

Example

  • [1,2,1,3,2,1], k=2 -> 2 (value 1 reaches count 2 first, then value 2)
added …
LeaderboardSalaryAccount