893. Check if BST Contains Dead End

EasyTreesBSTDFS

Given the root of a binary search tree built from distinct positive integers, determine whether it contains a dead end — a leaf node into which no new value could ever be inserted because the allowed range below it is empty. Return true or false. The input is a level-order BST array.

Input: A level-order BST array (positive keys).

Output: Boolean — true or false.

Examples

Example 1
Input: [8,5,9,2,7,null,null,1]
Output: true
Explanation: Leaf 1 cannot accept any insertion.
Example 2
Input: [8,5,9,7,11,null,null,2]
Output: false
Explanation: No dead-end leaf.
Example 3
Input: [5]
Output: false
Explanation: Root leaf can still accept values.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →