Howdy! Here’s your coding interview test question for today.
A universal value tree (aka “unival”) 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
Write your answer in any programming language or pseudocode on gist and paste the link in the comments below!