InferenceAI

Enter at least two characters to search.

Start free

Count Unblocked Nodes

mediumTrees25 min25 XP

A node is unblocked if no node on the path from the root to it (including the root) has a value greater than it. Return the number of unblocked nodes.

Trees are given in level order as a list, with None for a missing child (for example [3, 9, 20, None, None, 15, 7]).

Examples

EXAMPLE WALKTHROUGHfour nodes

A guided view of the published example, not a trace of your code.

INPUT[[3,1,4,3,null,1,5]]
TASKcount_unblocked_nodes()
EXPECTED OUTPUT4

Start with the input values shown in this example.

Example 1 of 3

Input: values = [3,1,4,3,null,1,5]

Output: 4

Explanation: four nodes

Input: values = [3,3,null,4,2]

Output: 3

Explanation: equal values count

Input: values = [1]

Output: 1

Explanation: single

Hint 1

Pass the maximum seen so far down the recursion.

Topics

DSATreesPython