Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

You are given a Singly Linked List of integers with a head pointer. Every node of the Linked List has a value written on it.

A sample Linked List:

Now you have been given an integer value, * 'K'*. Your task is to check whether a node with a value equal to 'K' exists in the given linked list. Return 1 if node exists else return 0.

Detailed explanation

```
3 6 2 7 9 -1
2
```

```
1
```

```
As value 2 exists in the given linked list. So we will return 1 in this case.
```

```
1 2 3 7 -1
7
```

```
1
```

```
As the value 7 exists in the Linked List, our answer is 1.
```

```
Try solving this in O(L).
```

```
1 <= 'L' <= 10^5
1 <= 'data' <= 10^9 and 'data' != -1
1 <= 'K' <= 10^9
Where 'L' represents the total number of nodes in the Linked List, 'data' represents the value at each node, and 'K' is the given integer.
Time Limit: 1 sec.
```