All problems
0585MediumArraySortingPrefix SumOrdered Set

Brightest Spot on the Walkway

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2021Brightest Position on Street

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A walkway is marked off with whole-number coordinates that run in both directions from zero. Lamps are described by lights, where lights[i] = [position_i, range_i] means lamp i stands at coordinate position_i and throws light on every whole-number coordinate from position_i - range_i through position_i + range_i, both ends included.

The brightness of a coordinate is the number of lamps whose light reaches it. Return the coordinate with the greatest brightness. If several coordinates share the greatest brightness, return the smallest of them.

Examples

Example 1

Input
lights = [[4, 2], [6, 2], [5, 0]]
Output
5

The first lamp lights 2 through 6, the second lights 4 through 8 and the third lights only 5. Coordinate 5 is reached by all three, so its brightness is 3 and no coordinate can beat that.

Example 2

Input
lights = [[0, 2], [4, 2]]
Output
2

One lamp lights -2 through 2 and the other lights 2 through 6. Coordinate 2 is the only one reached by both, so its brightness is 2.

Example 3

Input
lights = [[0, 1], [3, 1]]
Output
-1

The lamps light -1 through 1 and 2 through 4, and they never overlap, so the greatest brightness is 1 and it is shared by six coordinates. The smallest of them is -1.

Constraints

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

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def brightest_position(lights: list[list[int]]) -> int:
Java
public int brightestPosition(int[][] lights)
September 7
Apply