You are given a list of N integers and a value K. Print 1 if K exists in the given list of N integers, otherwise print −1.

INPUT:

- First-line will contain two numbers N and K
- Next line contains NN space-separated numbers.

Test Cases -

Sample Input 1:

4 2

1 2 3 4

Output

1

my code:

N,K = map(int,input().split())

list1 = list(map(int,input().split()))[:N]

flag = -1

#checking for the value of K in list1

for i in list1:

if i == K:

flag = 1

print(flag)

question link

my solution

2 Likes

I don’t know much about python so can’t point out the problem in your code but this got AC

```
n, k = map(int, input().split())
arr = list(map(int, input().split()))
ans = -1
for i in arr:
if i == k:
ans = 1
print(ans)
```

I don’t know much about python as I code in c++ but I can tell u the logic

- store the input in an array
- now traverse the array or list (in python) from start to end
- if u find the number k then return 1
- else if u reach the end of array and couldn’t find the number return 0

You Could Just Use The In Operator.

```
N, K = map(int, input().split(" "))
if str(K) in input():
print(1)
else:
print(-1)
```

The test cases are running fine, but it is giving wrong answer.

See

I just executed your code and it is totally fine. It is ac.

check here .

your solution ac

what is wrong??