Hudson River Trading: Coordinate lit by the most street lamps
Problem. Each street lamp has a centre c and a radius r and lights every point from c - r to c + r. Find the coordinate lit by the largest number of lamps. If several coordinates tie, return the smallest one.
Setting. The fourth of four problems in a 70-minute new grad assessment.
Approach. Turn each lamp into a +1 event at c - r and a -1 event just after c + r, sort the events, and sweep while tracking the running count. Record the first coordinate where the count hits a new maximum, taking care to process starts before ends at the same point so inclusive ranges are counted correctly.
Comments 0
No comments yet. Ask the author something, or add what happened in your own round.