Trains the technique from
LeetCode 515Find Largest Value in Each Tree RowThis 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 cargo rig is given as the flat list rig. It hangs from a single top joint, every joint carries at most two joints below it in a first and a second slot, and either slot may be empty.
A flat list is read level by level: its first entry is the top joint's load, 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 list that ends early leaves the remaining slots empty, and an empty list means no joints at all.
The decks of the rig are its levels: the top joint on its own, then the joints hanging directly off it, then the joints hanging off those, and so on.
Return the heaviest load on each deck, ordered from the top deck downwards. With no joints at all, return an empty list.
Example 1
The top deck is the joint loaded 4. Below it hang 9 and 6, the heavier being 9. The bottom deck holds 2, 8 and 7, and the second slot under the joint loaded 6 is empty, so the heaviest down there is 8.
Example 2
Two decks: the top joint on its own, then the pair below it, of which 4 is the heavier.
Example 3
Each joint's first slot is empty, so every deck holds exactly one joint and its load is the heaviest there by default.
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 largest_values(rig: list) -> list[int]:public int[] largestValues(Integer[] rig)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.