Trains the technique from
LeetCode 965Univalued 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 broadcast operator runs a relay network shaped as a binary tree. One relay sits at the head of the network, and every relay feeds up to two relays below it, a first branch and a second branch, either of which may be empty. Each relay is tuned to a channel, written as a number.
The network arrives as channels, a level-order listing. The first entry is the channel of the relay at the head. After that, the listing gives the first branch then the second branch of each relay already listed, in the order those relays appear, writing null wherever a branch is empty. Slots below a null are never written down, and the trailing run of null entries is left off.
The network is easiest to maintain when it runs on one channel throughout. Return true when every relay in the network is tuned to the same channel, and false otherwise.
Example 1
The listing names four relays and every one of them sits on channel 6. The `null` is the empty first branch below the relay listed second, not a relay.
Example 2
Each relay here feeds exactly one relay below it, giving a chain of channels 3, 3, 3, 3 and 9. The relay at the far end of the chain is on channel 9, which is not the channel at the head.
Example 3
The network is a single relay on channel 8, and it agrees with itself.
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_single_channel(channels: list[int | None]) -> bool:public boolean isSingleChannel(Integer[] channels)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.