Linear Search
Easyjavapythonccppjavascript
Given an array and a target value, find the first position where the target occurs.
Input Format
The first line contains two integers N and target. The second line contains N space-separated integers.
Output Format
Print the zero-based index of the first occurrence of target, or -1 if it is absent.
Example 1
Input
4 8 5 8 2 8
Output
1
Explanation: The first 8 is at index 1.
- 1 <= N <= 100000
- -1000000000 <= A[i], target <= 1000000000