Best Sprinkler Coordinate for Maximum Coverage
Problem statement
You are given a strictly increasing integer array flowers containing flower coordinates on a number line and a nonnegative integer radius.
Place one sprinkler at any integer coordinate c. It waters every flower whose coordinate lies in the inclusive interval [c - radius, c + radius].
Return a coordinate that waters the maximum possible number of flowers. If several coordinates water that maximum number, return the smallest such coordinate.
Function
bestSprinklerCoordinate(flowers: int[], radius: int) → intExamples
Example 1
flowers = [-6,-1,0,8]radius = 4return = -4A sprinkler at -4 waters the three flowers at -6, -1, and 0. No position waters all four, and -4 is the smallest position that waters three.
Example 2
flowers = [-3,2,3,4,9]radius = 2return = 2A sprinkler at 2 covers [0,4] and waters the three flowers at 2, 3, and 4.
Example 3
flowers = [7]radius = 3return = 4Every sprinkler coordinate from 4 through 10 waters the only flower. The smallest valid coordinate is 4.
Constraints
1 <= flowers.length <= 2 * 10^5.-10^9 <= flowers[i] <= 10^9.flowersis strictly increasing.0 <= radius <= 10^9.