51. First Occurrence
Foundation1000 ms256 MBSolved by 0%
You are given an array of n integers and a value k.
Print the 0-based index of the first position where k appears. If it does not
appear at all, print -1.
Constraints - `1 ≤ n ≤ 100000` - `-1000000 ≤ a[i], k ≤ 1000000`
Input
The first line contains an integer n.
The second line contains n space-separated integers.
The third line contains an integer k.
Output
Print one integer, the 0-based index of the first position holding k, or -1 if it never appears.
Input5
4 8 15 16 23
15
Output2
Notehas the value in the middle
Input4
1 2 3 4
9
Output-1
Notedoes not contain the value, so the answer is -1
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.