A sales report lets the user drag a price slider from low to high. Sold prices are stored in a binary search tree with unique values.
Write rangeTotal(root, low, high) that returns the sum of all values v with low <= v <= high. Skip subtrees that can't contain any value in the range. If nothing is in range, return 0.
Input: root = [10,5,15,3,7,null,18], low = 7, high = 15 Output: 32
7 + 10 + 15 = 32.
Input: root = [10,5,15,3,7,null,18], low = 19, high = 30 Output: 0
No price is that high.
0 <= number of prices <= 200001 <= low <= high <= 10^5Trees are written level by level, like [1, 2, 3, null, 4], where null is a missing child. Your function works with TreeNode objects, each with val, left, and right.
Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #337 Revenue Inside a Price Range. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.