Imagine you're a city planner tasked with finding the brightest spot on a perfectly straight street! ๐
The street is represented by a number line, and you have several street lamps positioned along it. Each lamp is described by a 2D array lights[i] = [position, range], where:
position- where the lamp is located on the streetrange- how far the light extends in both directions
A lamp at position p with range r illuminates the area from [p-r, p+r] (inclusive).
The brightness of any position is simply the number of lamps that light up that position. Your goal is to find the position with maximum brightness. If multiple positions tie for brightest, return the smallest position.
Example: If we have lamps at [[1,2], [3,1]], the first lamp lights [-1,3] and the second lights [2,4]. Position 2 and 3 both have brightness 2 (lit by both lamps), so we return 2.
Input & Output
Constraints
- 1 โค lights.length โค 105
- lights[i].length == 2
- -108 โค positioni โค 108
- 0 โค rangei โค 108