Problem - FIND ME
Problem Code - FINDMELI
You are given a list of integers and a value . Print if exists in the given list of integers, otherwise print .
Input:
- First-line will contain two numbers and .
- Next line contains space-separated numbers.
Output:
Print the answer in a new line.
Constraints
Sample Input 1:
4 2
1 2 3 4
Sample Output 1:
1
Sample Input 2:
4 4
1 2 6 9
Sample Output 2:
-1
EXPLANATION:
- In the first example, as is present in the list.
- In the second example, is not present in the list.
Solution :-
C++ :
#include <iostream>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
int a[N];
for (int i=0; i<N; i++) {
cin >> a[i];
}
for (int i=0; i<N; i++) {
if (a[i]==K) {
cout << "1";
goto re;
}
}
cout << "-1";
re:
return 0;
}


0 Comments