Greater sum tree
Given a binary search tree encoded as a level-order array (null for missing), convert it to a Greater Sum Tree where every node's new value is its original value plus the sum of all original values strictly greater than it. Return the result as a level-order array using the SAME shape as the input (null in the same positions), i.e. replace each non-null entry with its transformed value.
Implement
bst_to_greater_sum(level: list) → listExamples
in
[[4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]]out[30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 20 min
solution.py
InputExpectedGot
[[4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]][30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]not run yetsample