We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Graph Theory
- Even Tree
- Discussions
Even Tree
Even Tree
Sort by
recency
|
282 Discussions
|
Please Login in order to post a comment
PYTHON SIMPLE DFS SOLUTION
Approach
Solution
Here is the PHP code:
Explanation:
$subtreeSize
array.This solution assumes that the tree is given in a 1-based index as in the example. If your tree nodes are 0-based, you should adjust the code accordingly.
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star)
Cut each edge and check if the resulting subtree is even in length
This line should be added in the description very clearly