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

1 answer published. Last candidate submission on May 6 2026, 2:59am PDT. Interview question asked to Software Engineers interviewing at ClassPass, Zerodha, Kraken and other companies. Original question asked: Count nodes in a complete binary tree.. Question last reported by a candidate interviewing at Udacity for a Software Engineer interview on Oct 20 2026, 9:06pm PDT.