"Write a function to find a cycle inside a binary tree." I never worked with binary trees except academically, so this was a bit of a ringer.
Anonimo
If there is a cycle, then there are duplicate nodes. Simplest way is to create a List of the nodes and then walk the tree. Add each node to the tree AFTER checking if it exists -- if it exists, you know there are duplicate nodes. Once you have the list of duplicate nodes, then walk the child of any of these duplicates until you have exhausted them OR return to the starting node.