All problems
Count Complete Tree Nodes
Problem
Count the nodes of a complete binary tree given in level order.
tree is a list where real values are nodes and None marks missing positions; trailing Nones may be omitted.
Return the number of non-None entries.
Hint
In a complete tree every value present in the level-order list is a node.
Test cases
case 1
in: [[1,2,3,4,5,6]]
expected: 6
case 2
in: [[]]
expected: 0
case 3
in: [[1]]
expected: 1
case 4
in: [[1,null,2]]
expected: 2
Starter codePython
def count_complete_nodes(tree):
# Your code here
pass4 test cases · run your code against them in the editor