You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Good morning! Here's your coding interview problem for today.
This problem was asked by Adobe.
You are given a tree with an even number of nodes. Consider each connection between a parent and child node to be an "edge". You would like to remove some of these edges, such that the disconnected subtrees that remain each have an even number of nodes.
For example, suppose your input was the following tree:
1
/ \
2 3
/ \
4 5
/ | \
6 7 8
In this case, removing the edge (3, 4) satisfies our requirement.
Write a function that returns the maximum number of edges you can remove while still satisfying this requirement.
Activity
vaskoz commentedon Oct 19, 2019
The maximum number of edges for this test cases is actually 2.
Removing
(3, 4)and(1, 3)resulting in 3 separate subtrees of even nodes.3 Subtrees:
(1, 2)- 2 nodes(3, 5)- 2 nodes(4, 6, 7, 8)- 4 nodes