#C5927. Range in a Binary Search Tree
Range in a Binary Search Tree
Range in a Binary Search Tree
Given a binary search tree (BST) and two integers (L) and (R), your task is to find all the elements in the BST that lie in the inclusive range ([L, R]). The resulting elements should be returned in ascending order.
Note: The BST is provided as a level-order traversal where the value 'null' represents a missing node. For example, the BST
10 5 15 3 7 12 18
represents the tree:
10 /
5 15 / \ /
3 7 12 18
If (L = 7) and (R = 15), then the expected output is
7 10 12 15
.
inputFormat
Input is read from standard input (stdin). The first line contains the level-order traversal of the BST as space-separated values. Use the string "null" for missing nodes. The second line contains two space-separated integers (L) and (R), representing the lower and upper bounds of the range respectively.
outputFormat
Output the values within the range ([L, R]) in ascending order as a single line of space-separated integers, printed to standard output (stdout). If no values fall within the given range, output an empty line.## sample
10 5 15 3 7 12 18
7 15
7 10 12 15