Trains the technique from
LeetCode 993Cousins in Binary TreeThis 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 frame hangs from a single top lamp. Every lamp holds at most two lamps below it in a first and a second slot, and either slot may be empty. Every lamp carries a different label.
A flat list is read level by level: its first entry is the top lamp's label, 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.
Two lamps are cousins when they hang the same number of slots below the top lamp and they do not hang from the same lamp.
The labels x and y are different and both appear in the frame. Return true when the lamps carrying them are cousins.
Example 1
Both lamps hang two slots below the top. Lamp 4 hangs from lamp 2 and lamp 5 hangs from lamp 3, so they are cousins.
Example 2
The two lamps hang the same distance down, but both of them hang from the top lamp.
Example 3
Lamp 4 hangs two slots down while lamp 3 hangs only one, so the distances differ.
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 is_cousins(frame: list, x: int, y: int) -> bool:public boolean isCousins(Integer[] frame, int x, int y)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.