Hackerrank – Even Tree

Problem Statement
A description of the problem can be found on Hackerrank.

Solution
Make a map of a node vs. the nnumber of nodes connected to it. Iterate over the map. If for the ith node, the number of nodes connected is even, then iterate over the nodes list connected to this node. Now for every connected jth node, again get the number of nodes connected this jth node. If the number of nodes connected to jth node is odd, cut the edge.

I created solution in:

All solutions are also available on my GitHub.

Java

JavaScript

Scala

Ruby