A full node is a node that has both a left child and a right child. Count how many full nodes the binary tree contains.
One line: the binary tree as a level-order array.
The tree is encoded on ONE line as a space-separated level-order (breadth-first) array. The token null marks a missing child; the children of a null are omitted from the array. An empty tree is written as the single token null.
A single integer: the number of full nodes (0 for an empty tree).
Example 1
Input
1 2 3 4 5 null 6
Expected
2
Explanation
Node 1 has children 2 and 3, and node 2 has children 4 and 5, so both are full. Node 3 has only a right child. The count is 2.
Example 2
Input
1 2 3
Expected
1
Explanation
Only the root has two children, so the answer is 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →