Skip to content
DeepForgeby svx
All problems
HardNLPnlp-269

Plan Tree Statistics

Problem

Summarize a nested plan where leaves are strings and internal nodes are lists. Depth counts nesting levels: a list of leaves has depth 1, and an empty plan has depth 0.

Return [depth, leaf_count] for the whole plan.

Hint

Recurse over lists; a leaf contributes depth 0 and one leaf to its parent.

Test cases

case 1
in: [["a",["b",["c"]]]]
expected: [3,3]
case 2
in: [[]]
expected: [0,0]
case 3
in: [["a"]]
expected: [1,1]
case 4
in: [["a",["b","c"],["d",["e","f"]]]]
expected: [3,6]
case 5
in: [[["x","y"],["z"]]]
expected: [2,3]
Starter codePython
def plan_tree_stats(plan):
    # Your code here
    pass

5 test cases · run your code against them in the editor