Brightest Position on Street - Problem

A perfectly straight street is represented by a number line. The street has street lamp(s) on it and is represented by a 2D integer array lights. Each lights[i] = [position_i, range_i] indicates that there is a street lamp at position position_i that lights up the area from [position_i - range_i, position_i + range_i] (inclusive).

The brightness of a position p is defined as the number of street lamps that light up the position p.

Given lights, return the brightest position on the street. If there are multiple brightest positions, return the smallest one.

Input & Output

Example 1 — Basic Two Lamps
$ Input: lights = [[1,1],[3,2]]
Output: 1
💡 Note: Lamp 1 at position 1 with range 1 covers [0,2]. Lamp 2 at position 3 with range 2 covers [1,5]. Position 1 and 2 both have brightness 2, but we return the smaller position 1.
Example 2 — Single Lamp
$ Input: lights = [[2,3]]
Output: -1
💡 Note: Single lamp at position 2 with range 3 covers [-1,5]. All positions have brightness 1, so return the smallest position -1.
Example 3 — Multiple Overlaps
$ Input: lights = [[1,0],[0,1]]
Output: 0
💡 Note: Lamp 1 at position 1 with range 0 covers [1,1]. Lamp 2 at position 0 with range 1 covers [-1,1]. Position 0 and 1 both have brightness 1, return smaller position 0.

Constraints

  • 1 ≤ lights.length ≤ 105
  • lights[i].length == 2
  • -108 ≤ positioni ≤ 108
  • 0 ≤ rangei ≤ 108

Visualization

Tap to expand
Brightest Position on Street ProblemStreet (number line)Lamp 1pos=1, range=1Lamp 2pos=3, range=2Coverage [0,2]Coverage [1,5]OverlapBrightness = 2Answer: Position 1 (smallest with maximum brightness)Find where most lamp coverage areas overlap
Understanding the Visualization
1
Input
Street lamps with position and range
2
Coverage
Each lamp illuminates an area around its position
3
Brightness
Count overlapping lamps at each position
Key Takeaway
🎯 Key Insight: Use line sweep with difference array to efficiently track brightness changes at critical positions
Asked in
Google 15 Amazon 12 Microsoft 8
23.4K Views
Medium Frequency
~25 min Avg. Time
856 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen