Coding

Count nodes in a complete binary tree.

Given the root of a complete binary tree, return the number of the nodes in the tree. In a complete binary tree, every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible.

Input: root = [1,2,3,4,5,6,7]

Output: 7

Explanation: The lowest level is completely filled, forming a perfect binary tree with 8 - 1 = 7 nodes.

Was asked at

Practice this question with AI

First session is free - no credit card required.

Go Premium

More interviews, more skills, more success.

No answers yet

Be the first to share your approach to this question

Practice More Questions