Trains the technique from
LeetCode 337House Robber IIIThis 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 firm's reporting lines form a binary chart: every person has at most two direct reports, one recorded on their left and one on their right.
The chart arrives as chart, a level-by-level listing. chart[0] is the chief. After that, every person already listed contributes two entries in turn, their left direct report then their right direct report, with null where that report does not exist. A null contributes nothing further, and null entries at the very end of the listing are left off. Each entry is the discretionary bonus recorded for that person, which is never negative.
The board will pay a selection of these bonuses in one round, under a single rule: if a person is paid, neither of their direct reports may be paid in that round.
Return the largest total the board can pay out.
Example 1
Pay the person recorded as 7 and the person recorded as 10. Neither is a direct report of the other, and the two bonuses come to 17.
Example 2
The chief's two direct reports hold 4 and 5. Neither reports to the other, so both may be paid in the same round, for 9.
Example 3
The chief is the only person on the chart, and paying them comes to 5.
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 best_bonus_pool(chart: list[int | None]) -> int:public int bestBonusPool(Integer[] chart)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.