Get Components in Forest (for Virtual Interview)

Problem Overview

  • Remove specified edges from a binary tree and return the size of each connected component (forest) formed.
  • Input: a binary tree with n nodes (unique values) and an edges list of [from, to]; Output: an array of component sizes.
  • Domain: tree/graph partitioning used in network or hierarchy analysis.
  • This is a Google interviews coding interview problem and a common interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: