Range Sum of BST
Updated
Problem statement
Given the root of a binary search tree and two integers low and high, return the sum of the values of every node whose value is in the inclusive range [low, high].
A node outside the range may still have descendants inside the range. Use the binary search tree ordering to skip subtrees only when it is safe.
Function
rangeSumBST(root: TreeNode, low: int, high: int) → intExamples
Example 1
root = [10,5,15,3,7,null,18]low = 7high = 15return = 32The values in the inclusive range are 7, 10, and 15. Their sum is 32.
Example 2
root = [10,5,15,3,7,13,18,1,null,6]low = 6high = 10return = 23The values in the range are 6, 7, and 10. Their sum is 23.
Example 3
root = [8]low = 9high = 12return = 0The tree has a single node, and its value is below the range. Nothing is added, so the sum is zero.
Constraints
- The tree contains between
1and20000nodes. - Node values are unique integers between
1and100000. 1 <= low <= high <= 100000.- The tree is a valid binary search tree.
More Meta Phone Screen questions
- Convert a Sorted Linked List to a Balanced BSTPHONE SCREEN · Seen Nov 2026
- Fuzzy Word Lookup With One Misspelled LetterPHONE SCREEN · Seen Nov 2026
- Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
- First Element Greater Than KPHONE SCREEN · Seen Nov 2026
- Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
- Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
- Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Merge Two Binary TreesSnowflake · PHONE SCREENSnowflake interview questions
- Sum All Values in a Binary TreeDuolingo · PHONE SCREENDuolingo interview questions
- Sum Root-to-Leaf Binary NumbersOracle · PHONE SCREENOracle interview questions
- Symmetric Binary TreeDocuSign · PHONE SCREENDocuSign interview questions
- Count One-Valued Regions in a Binary TreeGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Maximum Depth of Binary TreeLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
- Maximum Value in a Binary TreeAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Root-to-Leaf Paths as StringsAdobe · PHONE SCREENAdobe interview questions
- Org Chart Report CountsPatreon · PHONE SCREENPatreon interview questions
- Left View of a Binary TreeMygate · PHONE SCREENMygate interview questions
Meta interview experiences
- Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
- Meta Business Support Engineer Phone Screen: 1 Experience
- Meta Software Engineer Onsite Questions: 3 Experiences
- Meta AI Native Engineer OA and Onsite: 1 Experience
- Meta AI-Native Coding Interview: 3 Experiences
- Meta Production Engineer Intern Questions: 6 Experiences