FunctionRacerProblemsRace

Second Appearance

BeginnerArraysPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Arrays problems