FastPrepFastPrep
Problem Brief

Find Point Illuminated by Most Lamps

OA

There are some lamps placed on a coordinate line. Each of these lamps illuminates some space around it within a given radius. You are given the coordinates of the lamps on the line, and the effective radius of the lamps' light.

In other words, you are given a two-dimensional array lamps, where lamps[i] contains information about the ith lamp. lamps[i][0] is an integer representing the lamp's coordinate, and lamps[i][1] is a positive integer representing the effective radius of the ith lamp. That means that the ith lamp illuminates everything in a range from lamps[i][0] - lamps[i][1] to lamps[i][0] + lamps[i][1] inclusive.

Your task is to find the coordinate of the point that is illuminated by the highest number of lamps. In case of a tie, return the point among them with the minimal possible coordinate.

1Example 1

Input
lamps = [[-2, 3], [2, 3], [2, 1]]
Output
1
Explanation

The first lamp illuminates everything in range [-5, 1]. The second lamp illuminates everything in range [-1, 5]. The third lamp illuminates everything in range [1, 3].

The only point that is illuminated by all of the lamps is 1, hence the answer is 1.

2Example 2

Input
lamps = [[-2, 1], [2, 1]]
Output
-3
Explanation

The given lamps illuminate ranges [-3, -1] and [1, 3] respectively. Every point in these ranges are illuminated by only 1 lamp, but the one with the minimal coordinate among them is -3, so it is the answer.

public int solution(int[][] lamps) {
    // write your code here
}
Input

lamps

[[-2, 3], [2, 3], [2, 1]]

Output

1

Sign in to submit your solution.