
Asked in Maersk
Binary Tree Node Presence Problem
Determine if a node with a given integer value X exists in a specified binary tree.
Input:
The first line of each test case contains the binary tree nodes in level order sequence as integers, with `-1` representing a null node.
The second line contains the integer X you have to search for in the tree.
Output:
Return 'true' if a node with value X exists in the binary tree, otherwise return 'false'.
Example:
Input:
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
5
Output:
true
Constraints:
1 <= N <= 10^5
- Where N is the total number of nodes in the binary tree.
- Time Limit: 1 sec.
Note:
You do not need to print anything explicitly in your solution code.

AnswerBot
4mo
Check if a node with a given value exists in a binary tree.
Traverse the binary tree using depth-first search (DFS) or breadth-first search (BFS) to search for the node with the given value.
Use a recur...read more
Help your peers!
Add answer anonymously...
Top Software Developer Interview Questions Asked at Maersk
Q. What is a decorator in Python?
Q. Architecture of current project
Q. Shortest Path in an Unweighted Graph The city of Ninjaland is represented as an ...read more
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Maersk Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

