Trains the technique from
LeetCode 740Delete and EarnThis 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 spectrum regulator is clearing a pile of licence applications for one radio band. requests holds one entry per application, and the entry is the channel number that application asks for. Several applications may ask for the same channel.
The regulator settles the pile one application at a time. Approving an application collects a fee equal to its channel number, and because a live transmitter spills into the slots on either side of it, approving an application for channel c immediately strikes out every application still in the pile asking for channel c - 1 and every one asking for channel c + 1. The approved application leaves the pile too. Any other application asking for channel c itself stays in the pile and may still be approved later.
The regulator repeats this until the pile is empty, so every application ends up either approved or struck out. Return the largest total fee the regulator can collect.
Example 1
Approve one channel 9 application for a fee of 9, striking out the channel 8 one. The second channel 9 application and the channel 12 application still stand and are approved, giving 9 + 9 + 12 = 30.
Example 2
Channels 1, 3 and 6 are each more than one apart, so no approval strikes out anything and all five applications pay: 1 + 3 + 3 + 6 + 6 = 19.
Example 3
Approving a channel 5 application only strikes out applications for channels 4 and 6, of which there are none, so all three are approved for 5 + 5 + 5 = 15.
Example 4
Approve one channel 4 application: it pays 4 and strikes out all four channel 5 applications. The other two channel 4 applications and both channel 6 applications survive and are approved, giving 4 + 4 + 4 + 6 + 6 = 24.
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 guard_band_fees(requests: list[int]) -> int:public int guardBandFees(int[] requests)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.