Back to course sections
    Mark As Completed Discussion

    Good afternoon! Here's our prompt for today.

    Question

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

    Description

    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.

    Description

    Try to solve this here or in Interactive Mode.

    How do I practice this challenge?

    JAVASCRIPT
    OUTPUT
    :001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

    Here's how we would solve this problem...

    How do I use this guide?

    Access all course materials today

    The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.

    Returning members can login to stop seeing this.