Triple Sum Problem Statement

Bojack wants to gift Todd a binary tree with N nodes for his birthday. However, the tree is too large, so he decides to select exactly three nodes such that their sum equals a given integer X. Help Bojack determine if such a selection of nodes is possible.

Input:

1. An integer T representing the number of test cases.
2. For each test case:
  - The elements of the binary tree in level order, separated by spaces.
  - An integer X.

Output:

A boolean True or False for each test case, indicating the possibility of obtaining the sum X using values from any three nodes.

Example:

Input:
T = 1
Nodes = [2, 3, -1, 4, -1, -1, 5, -1, -1, -1]
X = 11
Output:
True
Explanation:

The nodes with values 7, 3, and 1 add up to 11, making it possible to form the sum X.

Constraints:

  • 1 ≤ T ≤ 100
  • 1 ≤ N ≤ 3000
  • 1 ≤ NodeVal ≤ 1000
  • 1 ≤ X ≤ 1000
  • Time Limit: 1sec
Note:
You do not need to print anything. Just implement the function and return the correct output.
AnswerBot
1y

The task is to determine if it is possible to select three nodes from a binary tree such that their sum equals a given value.

  • Traverse the binary tree and store all the node values in an array

  • Use three...read more

Help your peers!
Select
Add answer anonymously...

Jio Software Developer interview questions & answers

A Software Developer was asked 2mo agoQ. Given a singly linked list, reverse the list and return the reversed list.
A Software Developer was asked 4mo agoQ. Count the occurrences of each element, and if the count is equal to a specified ...read more
A Software Developer was asked 7mo agoQ. What are abstraction and interfaces in Java?

Popular interview questions of Software Developer

A Software Developer was asked 2mo agoQ1. Given a singly linked list, reverse the list and return the reversed list.
A Software Developer was asked 4mo agoQ2. Count the occurrences of each element, and if the count is equal to a specified ...read more
A Software Developer was asked 7mo agoQ3. What are abstraction and interfaces in Java?
Jio Software Developer 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