Back to problems

Answer Repeated Range Aggregate Queries on a Static BST

Algorithm · Meta · Hard

You are given sortedValues, an array produced by an in-order walk of a static binary search tree. Because of that traversal, the array is sorted in nondecreasing order and duplicate keys are stored as separate consecutive entries, one per original node. You are also given queries; each query is a pair [low, high] that selects a closed interval. For a query, let the selected slice consist of every element sortedValues[i] satisfying $$low \le sortedValues[i] \le high$$. The…

Checking your access…