Trains the technique from
LeetCode 198House RobberThis 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 carrier runs a line of relay towers strung along one highway, listed west to east in the integer array credits. Switching on the tower at position i earns credits[i] units of billable bandwidth for the month.
Towers that sit side by side in the line share an overlapping band. Because of that, whenever you switch a tower on, both towers immediately beside it have to stay dark. Any selection obeying that rule is permitted, and leaving every tower dark is permitted too.
Return the greatest total the carrier can bill.
Example 1
Lighting the second and fourth towers bills 8 + 8 = 16. Grabbing the fat 9 in the centre forces both eights dark and only reaches 9 + 2 + 2 = 13.
Example 2
Positions 0, 3 and 5 are pairwise non-neighbouring and bill 3 + 3 + 3 = 9.
Example 3
A lone tower has no neighbour to interfere with, so it can be lit.
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 max_credits(credits: list[int]) -> int:public int maxCredits(int[] credits)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.