Mid/Senior

Brightest Position on Street

A perfectly straight street is represented by a number line. You are given a 2D integer array lights, where lights[i] = [position_i, range_i] means there is a street lamp at position_i that illuminates every integer position from position_i - range_i to position_i + range_i, inclusive.

The brightness of a position is the number of street lamps that illuminate it.

Return the brightest position on the street. If there are multiple positions with the maximum brightness, return the smallest such position.

Your solution should be efficient enough for up to 10^5 lights.

Example 1
Inputlights = [[-3,2],[1,2],[3,3]]
Output-1
The maximum brightness is 2, achieved at several positions, and the smallest of them is -1.
Example 2
Inputlights = [[1,0],[0,1]]
Output1
Position 1 is illuminated by both lamps, giving it the highest brightness.

Constraints

  • 1 <= lights.length <= 10^5
  • lights[i].length == 2
  • -10^8 <= position_i <= 10^8
  • 0 <= range_i <= 10^8

Asked at 7 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate