Target in middle
Input
arr = [5, 3, 7, 3, 9], target = 3
Output
1
3 first appears at index 1.
Full lesson preview
Return the index of the first occurrence of a target value in an array.
Problem statement
Task
Examples
Input
arr = [5, 3, 7, 3, 9], target = 3
Output
1
3 first appears at index 1.
Input format
Output format
Constraints
Samples
Input
first_index_of_target([1,2,3], 2)
Output
1
2 is at index 1.