Lamps and Control Points
Problem statement
Each lamp illuminates a closed interval on a number line. The row lamps[i] = [left, right] means that lamp covers every coordinate from left through right, including both endpoints.
For every coordinate in points, count how many lamp intervals contain it. Return the counts in the same order as points. Repeated lamp intervals represent separate lamps, and repeated points each receive their own result.
Function
lampCoverage(lamps: int[][], points: int[]) → int[]Examples
Example 1
lamps = [[1,7],[5,11],[7,9]]points = [7,1,8,11,12]return = [3,1,2,1,0]All three lamps cover 7. Only the first covers 1, the last two cover 8, only the second covers 11, and none covers 12.
Example 2
lamps = [[2,2],[2,4],[2,4]]points = [4,2,4,1]return = [2,3,2,0]Duplicate intervals count separately, a zero-length interval covers its endpoint, and repeated point queries retain their original order.
Constraints
1 <= lamps.length, points.length <= 10^5- Each lamp row has exactly two integers with
left <= right. - Every endpoint and point is between
-10^9and10^9, inclusive.