Birds on a Wire ⧉
The problem input provides us the length of the wire, the minimum distance between two birds, and the positions of each bird so far.
All we need to do to maximize the number of additional birds on the wire is to greedily place a new bird wherever it can fit, i.e. the minimum distance from the previous bird.
Although we don't need to place one bird at a time--since the minimum distance is constant, the number of birds we can fit on an empty section of the wire that spans [start,end]
is (end-start)/minimum distance + 1
.
The tricky part is determining the start and end of each section. Once that is done, simply cram as many birds onto the wire as possible and report the total.
If you found this solution helpful, consider leaving a star!