O40

Count Complete Tree Nodes

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: ARRAY

Problem Statement & Objective

Given the root of a complete binary tree, return the number of the nodes in the tree in less than O(n) time complexity.

Function Signature (Python)

count_complete_tree_nodes(root: list) -> list

Input & Output Contract

Output Rule:[gerçek_düğüm_sayısı, tam_mı]. Boş dizi [0, true]. Kök null ise adet 0 olabilir ve tam_mı false'tur.

System Constraints

0 <= agac.length <= 5 * 10^4
Değerler -10^4..10^4 veya null
Dizi tam olmak zorunda değildir; tam_mi bunu bildirir

Example Execution Walkthrough

[1, 2, 3, 4, 5, 6] → [6, true]
[1, 2, 3, 4, null, null, null] → [4, true]  (len = 7, adet = 4)
[1, null, 2] → [2, false]  (sağ çocuk varken sol yok)
[] → [0, true]

Example Test Scenarios (4)

Example 1: Null'suz Tam Ağaç
Input:[[1,2,3,4,5,6]]
Expected Output:[6,true]
Example 2: Boş
Input:[[]]
Expected Output:[0,true]
Example 3: Sonda Null Dolgusu
Input:[[1,2,3,4,null,null,null]]
Expected Output:[4,true]
Example 4: Delik, Tam Değil
Input:[[1,null,2]]
Expected Output:[2,false]
Loading Python Editor...
Input Parameters
[
  [
    1,
    2,
    3,
    4,
    5,
    6
  ]
]
Expected Output
[
  6,
  true
]