Trains the technique from
LeetCode 102Binary Tree Level Order TraversalThis 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 fibre trunk fans out through a set of splice enclosures. One enclosure sits at the head of the run, and every enclosure passes the fibre on to at most two enclosures further out: one wired to its left tray and one wired to its right tray. Each enclosure is labelled with a signed loss figure in hundredths of a decibel.
Because the harness passes plain JSON, the run arrives as the array splices, written out depth by depth. splices[0] is the loss figure at the head enclosure. After it the entries come in pairs, giving the left tray and then the right tray of each enclosure already written out, taken in that same order. An empty tray is written null, and a null claims no pair of its own. Trailing null entries are left off the end, and an empty array means no enclosures were fitted.
The depth of the head enclosure is 0, and an enclosure wired to a tray of a depth-d enclosure sits at depth d + 1.
Return a list whose i-th entry is the list of loss figures of every enclosure at depth i, each depth given in the order those enclosures appear in splices. Return an empty list when no enclosures were fitted.
Example 1
The head enclosure reads 4. Its two trays carry -7 and 12, so depth 1 holds both figures in that order. The left tray of the -7 enclosure is empty and its right tray carries 5, the only enclosure at depth 2.
Example 2
One enclosure was fitted and it reads 0, so depth 0 is the only depth reported.
Example 3
The head enclosure has an empty left tray, so the entry 8 belongs to its right tray. The 8 enclosure is then the next one written out, and the pair 6 and -1 fills its two trays at depth 2.
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 splice_depths(splices: list) -> list[list[int]]:public List<List<Integer>> spliceDepths(Integer[] splices)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.