Partial BST Problem Statement

Check if a given binary tree is a Partial Binary Search Tree (BST). A Partial BST adheres to the following properties:

  • The left subtree of a node contains only nodes with data less than or equal to the node’s data.
  • The right subtree of a node contains only nodes with data greater than or equal to the node’s data.
  • Both left and right subtrees must also be Partial BSTs.

Input:

The first line contains an integer 't', the number of test cases. Each test case is described by the next lines:
The elements of the tree in level order form, space-separated. Use -1 to denote the absence of a child node.

Output:

For each test case, return 'true' if the binary tree is a Partial BST, 'false' otherwise. Each result will be on a separate line.

Example:

Input:
1
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output:
true

Constraints:

  • 1 ≤ T ≤ 100
  • 1 ≤ N ≤ 1000
  • -109 ≤ data ≤ 109
Note:

You are not required to print anything; the implementation should simply return the result.

AnswerBot
4mo

Check if a binary tree is a Partial Binary Search Tree (BST) based on specific properties.

  • Traverse the tree in level order and check if each node satisfies the properties of a Partial BST.

  • Use recursio...read more

Help your peers!
Select
Add answer anonymously...

Jupiter Money Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Partial BST Problem Statement Check if a given binary tree is a Partial Binary S...read more
A Software Developer Intern was asked Q. Merge Two Sorted Linked Lists Problem Statement You are provided with two sorted...read more
A Software Developer Intern was asked Q. Shortest Path in an Unweighted Graph The city of Ninjaland is represented as an ...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Partial BST Problem Statement Check if a given binary tree is a Partial Binary S...read more
A Software Developer Intern was asked Q2. Merge Two Sorted Linked Lists Problem Statement You are provided with two sorted...read more
A Software Developer Intern was asked Q3. Shortest Path in an Unweighted Graph The city of Ninjaland is represented as an ...read more
Jupiter Money Software Developer Intern 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