Trains the technique from
LeetCode 404Sum of Left LeavesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A mobile hangs from a single top weight. Every weight holds at most two weights below it in a first and a second slot, and either slot may be empty. Each weight shows a number.
A flat list is read level by level: its first entry is the top weight's number, and reading left to right, every entry that is not null claims the next two unused positions as its first and second slot in that order, while null marks an empty slot and claims no positions of its own.
A weight is a tip when both of its slots are empty. Return the total of the numbers on the tips that hang in a first slot.
Example 1
The four weights at the bottom are the tips. Two of them hang in a first slot, showing 4 and 6, so the total is 10.
Example 2
The one weight below the top hangs in a second slot, so nothing counts.
Example 3
The single weight below the top hangs in a first slot with nothing under it.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def sum_of_left_leaves(mobile: list) -> int:public int sumOfLeftLeaves(Integer[] mobile)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.