How to find the maximum value in each branch of a tree and output their indexes as a tree?

Hello!

I am struggling to get the maximum value in each branch from one tree, and then output the indexes of those values as a tree. If there is no maximum value, then output ‘null’, as the pic shows.

Thanks for your help in advance!
Example.gh (10.6 KB)

Example_mrtn.gh (23.4 KB)


Example_re2.gh (12.7 KB)

what am i doing wrong not coming for me

Thanks a lot! It really helps!

Thanks a lot! So happy to see the different method!