Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Search in a Linked List
EASY
10 mins
11 upvotes
Linked List
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Linked List
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Search in a Linked List

Contributed by
Arindam Majumder
Easy
yellow-spark
0/40
Avg time to solve 10 mins
Success Rate 90 %
Share
11 upvotes

Problem Statement

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

Sample Linked List

Now you have been given an integer value 'K'. Your task is to check whether a node having a value equal to 'K' exists in the given linked list or not.

Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
2
3 6 2 7 9 -1
2
1 3 8 7 -1
5
Sample Output 1:
1
0
Explanation for Sample Input 1:
For the first test case, the given Linked List is

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

And for the second test case, the given Linked List is

alt-txt

As the value 5 is not present in the Linked list. So our answer is 0 in this case.
Sample Input 2:
1
1 2 3 7 -1
7
Sample Output 2:
1
Explanation for Sample Input 2:
For the first test case, the given Linked List is 

alt img

As the value 7 exists in the Linked List, so our answer is 1 in this case.
Reset Code
Full screen
Auto
copy-code
Console