Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Use an occurrence array.
Iterate over the elements in reverse order.
If the current element <code>nums[i]</code> is not marked in the occurrence array and <code>nums[i] <= k</code>, mark <code>nums[i]</code>.
Keep track of how many integers you have marked.
Return the current index as soon as the number of marked integers becomes equal to <code>k</code>.