Place a Lamp to Cover the Most Objects
Problem statement
objects contains unique coordinates in strictly increasing order. A lamp at integer coordinate x illuminates every object whose distance from x is at most radius.
Return an integer lamp coordinate that illuminates the most objects, breaking ties by the smallest coordinate.
Function
bestLampCoordinate(objects: int[], radius: int) → intExamples
Example 1
objects = [-5,3,4,9]radius = 5return = -1The window [-5,4] is covered by lamp coordinate -1 and contains three objects.
Example 2
objects = [7]radius = 2return = 5The smallest lamp coordinate covering the object is five.
Constraints
1 <= objects.length <= 100000-1000000000 <= objects[i] <= 10000000000 <= radius <= 1000000000