Sequential Search
Submit solution
Points:
3
Time limit:
1.0s
Memory limit:
256M
Author:
Problem type
Allowed languages
Java
Given an integer array \(A\) of size \(N\) and a target value \(x\), output the index of \(x\) in the array. If \(x\) does not exist, output -1
.
Constraints
\(1 \le N \le 10 ^ 6\)
\(-10 ^ 4 \le A_{i}, x \le 10 ^ 4\)
Input Specification
The first line of input consists of two integers \(N\) and \(x\), representing the size of the array and the target value respectively.
The next \(N\) lines will each consist of a single integer \(A_{i}\), representing the value of index \(i\) in the array.
Output Specification
Output the index of \(x\) in the array. If \(x\) is not in the array, output -1
.
Sample Input
5 2
1
6
0
-2
2
Sample Output
4
Explanation for Sample Output
The number 2
is found at index 4
in the array \([1,6,0,-2,2]\). Note that the array is zero-indexed.
Comments