Unique One-Region Sizes in a Binary Tree
Updated
Problem statement
You are given a binary tree whose node values are only 0 or 1. A one-region contains all nodes with value 1 that can reach one another through parent-child edges without passing through a 0 node.
Return the distinct region sizes in increasing order. Return an empty array for an empty tree or a tree with no value 1 nodes.
Function
uniqueOneRegionSizes(root: TreeNode) → int[]Examples
Example 1
root = [1,1,0,1,0,1,1]return = [1,3]The root, its left child and that child's left child are all 1, so they form one region of size 3. The two 1s under the right child are not connected to each other, because their parent is 0, so each is a region of size 1. The distinct sizes are [1,3].
Example 2
root = [0,0,0]return = []No node has value 1.
Example 3
root = []return = []An empty tree has no regions.
Constraints
- The tree has at most
2000nodes. - Every node value is
0or1.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Account Roles With Parent-User InheritanceStripe · PHONE SCREENStripe interview questions
- Validate a BST with a Custom ComparisonApple · PHONE SCREENApple interview questions
- Merge N-Ary Trees by KeyLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
- Filesystem Hash TreeCursor · PHONE SCREEN · ONSITE INTERVIEWCursor interview questions
- Render a Stable Comment HierarchyBobyard · PHONE SCREEN
- Translate Values in a Nested MapZip · PHONE SCREENZip interview questions
- Build a Trace ForestDatadog · PHONE SCREENDatadog interview questions
- Topmost Accessible NodesFigma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
- Team Cost Under a ManagerRippling · PHONE SCREENRippling interview questions