FastPrepUnique One-Region Sizes in a Binary Tree
Problems/Unique One-Region Sizes in a Binary Tree

Unique One-Region Sizes in a Binary Tree

Google logoGoogle● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report defines one-islands in a 0/1 tree and follows up by asking for all unique island sizes. We use maximal connected parent-child groups and a sorted list of distinct sizes. Our version is about 93% the same as the reported question.

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]
root
1110011

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 = []
root
000

No node has value 1.

Example 3

root = []return = []
root
empty

An empty tree has no regions.

Constraints

  • The tree has at most 2000 nodes.
  • Every node value is 0 or 1.

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

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public int[] uniqueOneRegionSizes(TreeNode root) {
        // Write your code here.
    }
}
Checking account…