Second Appearance
Return the index of the second time target appears in nums, counting from the left (indexes start at 0). If target appears fewer than two times, return -1.
Example 1
nums [4,7,4,9,4]
target 4
returns 2
4 appears at indexes 0, 2 and 4; the second of these is 2.
Example 2
nums [1,2,3]
target 2
returns -1
2 appears only once, so there is no second appearance.
Constraints
0 <= len(nums) <= 100-1000 <= nums[i] <= 1000-1000 <= target <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Arrays problems
- Shift Right and FillBeginner
- Shuffle the ArrayBeginner
- Sort by ParityBeginner
- Trend SignsBeginner
- Alternate the SignsEasy
- Drop the Lowest ScoresEasy
- Fair CutsEasy
- Final Tank LevelEasy