Practice ยท 1 of 4
First duplicate
CHALLENGE
Difficulty: beginner+25 XP
Implement static int FirstDuplicate(int[] nums) โ return the value whose **second occurrence appears earliest** when scanning left to right; -1 if no value repeats. For [2,1,3,1,2] the answer is 1 (its second occurrence at index 3 beats 2's at index 4).
Press Submit to check your solution.
Back to lesson: Practice: Algorithm workshop