Description
Solutions
Get Components in Forest (for Virtual Interview)
๐RELATED PROBLEMS
Given a binary tree with n
nodes and an array edges
where each element is of the form [from, to]
, representing an edge from from
to to
.
Remove all the edges in the edges
array from the tree and return an array with the total node count in each connected component formed after removing all the edges from the tree.
Note: All the node values in the Binary Tree are unique.
Example 1:
Input: Nodes = ["1", "2", "3", "4", "5", "null", "null"], Edges = [[1, 2], [2, 4]]
Output: [2,2,1]
Explanation:The output shows that there are 3 components formed after removing the edges from the binary tree, and number of nodes in those components are 2, 2 and 1 respectively.
Constraints:
๐๐

Related Problems
Testcase
Result
Case 1
input:
output: