Skip to the code
cf.
+50 XP

#59 Brightest Spot on the Street

hard

A map widget draws street lamps along a very long street. Lamp [position, range] lights every whole-number position from position - range to position + range, both included. Positions can be as far apart as hundreds of millions.

Write brightestSpot(lamps) that returns the smallest position lit by the largest number of lamps.

Example 1

Input: lamps = [[2,3],[6,1],[9,2]]
Output: 5

The lamps light [-1, 5], [5, 7], and [7, 11]. Positions 5 and 7 each get two lamps; 5 is smaller.

Example 2

Input: lamps = [[0,0]]
Output: 0

One lamp lights only position 0.

Constraints

  • 1 <= lamps.length <= 10^5
  • -10^8 <= position <= 10^8
  • 0 <= range <= 10^8
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).