Counting unival subtrees I have written some code to solve the following interview question. Please advise how it can be improved. Thanks in advance.
A unival tree (which stands for &quot;universal value&quot;) is a tree where all nodes under it have the same value. Given the root to a binary tree, count the number of unival subtrees.
For example, the following tree has 5 unival subtrees:
    0
   / \
  1   0
     / \
    1   0
   / \
  1   1

Implementation:
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdbool.h&gt;

typedef struct stTree
{
    struct stTree * left;
    struct stTree * right;
    int value;
}

stTree;

stTree* createNode(int value)
{
    stTree *node = malloc(sizeof *node);
    node-&gt;left = NULL;
    node-&gt;right = NULL;
    node-&gt;value = value;

    return node;
}

bool isTreeUniv(stTree *node)
{
    bool flag = true;

    if (!node)
        return false;

    if (node-&gt;right &amp;&amp; node-&gt;right-&gt;value != node-&gt;value)
    {
        flag = false;
    }

    if (node-&gt;left &amp;&amp; node-&gt;left-&gt;value != node-&gt;value)
    {
        flag = false;
    }

    return flag;
}

stTree* insertRight(stTree *currNode, int value)
{
    stTree *node = malloc(sizeof *node);

    currNode-&gt;right = node;
    node-&gt;left = NULL;
    node-&gt;right = NULL;
    node-&gt;value = value;
    return node;
}

stTree* insertLeft(stTree *currNode, int value)
{
    stTree *node = malloc(sizeof *node);

    currNode-&gt;left = node;
    node-&gt;left = NULL;
    node-&gt;right = NULL;
    node-&gt;value = value;
    return node;
}

unsigned int uTreeCount = 0;
void countUnivSubT(stTree *Node)
{
    if (isTreeUniv(Node))
        uTreeCount++;

    if (Node-&gt;left)
        countUnivSubT(Node-&gt;left);

    if (Node-&gt;right)
        countUnivSubT(Node-&gt;right);

}

int main(void)
{
    //build a tree
    stTree *rootNode = createNode(0);
    insertLeft(rootNode, 1);
    insertRight(rootNode, 0);

    insertLeft(rootNode-&gt;right, 1);
    insertRight(rootNode-&gt;right, 0);

    insertLeft(rootNode-&gt;right-&gt;left, 1);
    insertRight(rootNode-&gt;right-&gt;left, 1);

    countUnivSubT(rootNode);
    printf(&quot;total universal subree: %u\n&quot;, uTreeCount);

}
The one red flag is uTreeCount. This should not be a global, and in fact it is easy to rephrase your countUnivSubT to be fully re-entrant: have it return an integer, and do addition within the body, something like
unsigned countUnivSubT(stTree *Node)
{
    unsigned int uTreeCount = isTreeUniv(Node);

    if (Node-&gt;left)
        uTreeCount += countUnivSubT(Node-&gt;left);

    if (Node-&gt;right)
        uTreeCout += countUnivSubT(Node-&gt;right);

    return uTreeCount;
}

That said, you have an inner null check, so this can actually reduce to
unsigned countUnivSubT(stTree *Node)
{
    if (!Node) return 0;
 
    return isTreeUniv(Node)
        + countUnivSubT(Node-&gt;left)
        + countUnivSubT(Node-&gt;right);
}