Community

Start a Thread


Notifications
Subscribe You’re not receiving notifications from this thread.

Counting Univalued Subtrees (Main Thread)

Here is the interview question prompt, presented for reference.

Question

Can you count all the univalued subtrees in a binary tree, as shown in the figure below?

The Problem

We are given a binary tree. The challenge is to count all the univalued subtrees in the tree. Just to recall, a subtree is any node along with its descendants. The root and all its descendants form the entire tree. A univalued subtree is therefore a subtree in which all the nodes have the same keys. The figure below shows all the univalued subtrees of the binary tree of the previous figure.

You can see the full challenge with visuals at this link.

Challenges • Asked almost 6 years ago by Jake from AlgoDaily

Jake from AlgoDaily Commented on Jul 11, 2018:

This is the main discussion thread generated for Counting Univalued Subtrees.