FastPrepFastPrep
Problem Brief

Lamps Illumination

OA

Imagine that there are several lamps placed on a number line, each of which illuminates some segment of the line. Specifically, the lamps are represented in a two-dimensional array lamps, where the ith lamp covers the segment from lamps[i][0] to lamps[i][1], inclusive.

Additionally, you are given a list of control points on this number line, represented by an array points. Your task is to find the number of lamps that illuminate each control point. Specifically, for each control point points[i] in the array, your task is to find the number of lamps lamps[i] which include this point within its covered segment - when points[i] lies inside the segment [lamps[i][0], lamps[i][1]].

As a result, return an array of integers, where ith integer corresponds to the answer for the ith control point.

1Example 1

Input
lamps = [[1, 7], [5, 11], [7, 9]], points = [7, 1, 5, 10, 9, 15]
Output
[3, 1, 2, 1, 2, 0]
Explanation
For each control point, the number of lamps that illuminate it is as follows: - Control point 7 is illuminated by lamps 0, 1, and 2. - Control point 1 is illuminated by lamp 0. - Control point 5 is illuminated by lamps 0 and 1. - Control point 10 is illuminated by lamp 1. - Control point 9 is illuminated by lamps 1 and 2. - Control point 15 is not illuminated by any lamp. Therefore, the answer is [3, 1, 2, 1, 2, 0].
public int[] solution(int[][] lamps, int[] points) {
  // write your code here
}
Input

lamps

[[1, 7], [5, 11], [7, 9]]

points

[7, 1, 5, 10, 9, 15]

Output

[3, 1, 2, 1, 2, 0]

Sign in to submit your solution.