#K92067. Range Sum of BST

    ID: 38115 Type: Default 1000ms 256MiB

Range Sum of BST

Range Sum of BST

Given a binary search tree (BST) and two integers low and high, compute the sum of all node values that lie in the inclusive range \( [low, high] \). The tree is provided as a level-order traversal where the string "null" represents a missing node. Your task is to build the BST using the provided input format and then return the computed sum.

inputFormat

The input consists of two lines:

  • The first line is a space-separated list of node values representing the BST in level-order. Use the string "null" for missing children.
  • The second line contains two integers separated by a space, which represent the values low and high respectively.

outputFormat

Output a single integer: the sum of all node values in the BST that lie in the inclusive range \( [low, high] \).

## sample
10 5 15 3 7 null 18
7 15
32