Linked List Value Search Problem Statement
Given a Singly Linked List of integers accessible via a head pointer, where each node contains a specific integer value. You are required to determine if a node with a specified value K
exists within the linked list.
Input:
The first line contains an integer 'T', the number of test cases. For each test case: The first line lists space-separated integers which are the node values of the linked list, ending with -1. Note that -1 is not a part of the list. The next line contains an integer 'K' that needs to be checked in the list.
Output:
Output 1 for each test case if the value 'K' is found, otherwise output 0, each answer on a new line.
Example:
Input: 2
1 2 3 4 -1
4
5 6 7 8 -1
10
Output: 1
0
Constraints:
- 1 <= T <= 10
- 1 <= L <= 105
- 1 <= data <= 109, data ≠ -1
- 1 <= K <= 109
Note:
The implementation should focus on checking the existence of 'K' and does not require printing as that has been pre-handled.
Be the first one to answer
Add answer anonymously...
Top TCS Associate Software Engineer interview questions & answers
Popular interview questions of Associate Software Engineer
Top HR questions asked in TCS Associate Software Engineer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app