Your question is Find Kth Duplicate in Array. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Hp IQ telemetry processors may need to identify repeated event values in the order they first become known to be duplicates. Given an integer array and an integer k, return the kth distinct value that appears at least twice, ordered by its first appearance in the array. Count each duplicated value once, even if it appears more than twice. Return -1 if fewer than k distinct values are duplicated.
Implement a function that accepts nums, a non-empty list of integers, and k, a positive integer. Return an integer representing the kth distinct duplicated value, or -1 when no such value exists. The output order is based on each value's first index in nums, not on frequency or the index of its second occurrence.
def kth_duplicate(nums, k):