Question: python code Recall that we defined a leaf labelled tree by saying an LLT is either a int, or a list [ LLT ]

python code
Recall that we defined a leaf labelled tree by saying "an LLT is either a int, or a list[LLT]", and that we wrote this in Python as:
LLT = int | list['LLT']
```
Write a function llt_max_value. It takes an LLT and a callable function that consumes a
single integer and returns the leaf in the tree that gives the greatest value when evaluated at
the callable function. In the case of a tie return the left most value when drawn.
```
For example,
def digit_sum(n: int)-> int:
"""Returns the sum of digits of n"""
n = abs(n)
s =0
while n >0:
s += n %10
n = n //10
return s
check.expect("T1", digit_sum(0),0)
check.expect("T2", digit_sum(1234567890),45)
check.expect("LLT digit sum",
llt_max_value([[[31],[45,7]],[[[[88],[311,[96]]],[10,6]]]],
digit_sum),88)
check.expect("LLT digit sum ties",
llt_max_value([[[31],[4,13]],[[[[1111],[112,[211]]],[121,22]]]],
digit_sum),31)
python code Recall that we defined a leaf

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!