Code RoomFewest boosters to lift nodes
HardPrep Room Coding #4900

Fewest boosters to lift nodes

CodingAlgorithms & data structuresSenior–Staff~35 min

A fibre network runs out from a single head end and its layout is a tree. Node 0 is the head end and uplink[0] is -1. For every other node i, uplink[i] names the node it hangs off, always a smaller number. A booster placed on a node lifts the signal on that node and on every node within reach hops of it, counting hops along the fibre in either direction. Return the fewest boosters that leave every node lifted. uplink may be empty, in which case no boosters are needed, and reach may be 0. Serving the most unlifted nodes you can with each booster is not the fewest.

Implement
min_boosters(uplink: list[int], reach: int) → int
Examples
in[[-1,0,1,0,3],1]out2
in[[-1,0,0,0],1]out1
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 35 min
InputExpectedGot
[[-1,0,1,0,3],1]2not run yetsample
[[-1,0,0,0],1]1not run yetsample