Ctrl K

The Most Lit Spot on the Street

Medium
A straight street is a number line with lamps placed along it. Lamp lamps[i] = [p, r] stands at point p and lights every integer point of the segment [p - r, p + r], ends included. The brightness of a point is the number of lamps that light it. Find the integer point with the highest brightness and return its coordinate. If several points tie, return the leftmost (smallest) one.
Example 1
lamps=[[0, 3], [6, 2], [5, 1]] → 4

The lamps cover [-3, 3], [4, 8] and [4, 6]. Points 4, 5 and 6 are lit twice, every other point at most once. The leftmost of the best points is 4.

Example 2
lamps=[[2, 0], [-1, 3]] → 2

The first lamp lights only point 2, the second lights [-4, 2]. Only point 2 is lit twice.

Example 3
lamps=[[10, 5]] → 5

The single lamp lights all of [5, 15] equally, so the answer is its left end.

Constraints
  • 1 ≤ len(lamps) ≤ 10⁵
  • lamps[i] = [p, r]
  • -10⁸ ≤ p ≤ 10⁸
  • 0 ≤ r ≤ 10⁸
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsFlowers in Bloom on Visit Day HardStudios for Recording Sessions MediumShuttle Seat Plan MediumKitchen Order Board MediumArrange for the Busiest Ranges Medium
loading Python…
Input
lamps=[[0, 3], [6, 2], [5, 1]]
Expected
4

Run checks the first 3 tests in your browser. Submit checks all 114 tests on the server, hidden ones included.