coderz.py

Keep Coding Keep Cheering!

Count Unival Subtrees in a Binary Tree

A unival tree (short for “universal value tree”) is a tree in which all nodes have the same value.

Given the root of a binary tree, determine how many unival subtrees it contains.

For example, the following tree has 5 unival subtrees:

January 6, 2025 | Binary Tree, dsa, DSA Sheet, Google | No comments

Advertisement