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.
AnswerBot
4mo

Given a singly linked list of integers, determine if a specified value exists within the list.

  • Iterate through the linked list to check if the specified value exists.

  • Return 1 if the value is found, els...read more

Help your peers!
Select
Add answer anonymously...

TCS Associate Software Engineer interview questions & answers

An Associate Software Engineer was asked 1w agoQ. What is IPL in Mainframe?
An Associate Software Engineer was asked 1mo agoQ. What is abstraction?
An Associate Software Engineer was asked 1mo agoQ. What is inheritance?

Popular interview questions of Associate Software Engineer

An Associate Software Engineer was asked 3d agoQ1. What is IPL in Mainframe?
An Associate Software Engineer was asked 1mo agoQ2. What is abstraction?
An Associate Software Engineer was asked 1mo agoQ3. What is inheritance?
TCS Associate Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits