You are given an integer n, representing n light bulbs arranged in a line and indexed from 0 to n - 1.
You are also given an integer brightness and a 2D integer array intervals, where intervals[i] = [starti, endi] represents an inclusive time interval during which the lighting requirement must be satisfied.
At each time unit, every bulb can independently be either on or off. A bulb that is on illuminates its own position and its adjacent positions, if they exist.
The total illumination at a time unit is the number of illuminated positions. Each position is counted at most once.
For every integer time unit covered by at least one interval in intervals, the total illumination must be at least brightness. At time units not covered by any interval, all bulbs may remain off. Each bulb that is on consumes 1 unit of energy for that time unit.
Return an integer denoting the minimum total energy required.
Example 1:
Input: n = 5, brightness = 5, intervals = [[6,12]]
Output: 14
Explanation:
0 1 0 0 1.12 - 6 + 1 = 7, so the total energy is 2 * 7 = 14.Example 2:
Input: n = 2, brightness = 1, intervals = [[0,0],[2,2]]
Output: 2
Explanation:
1 + 1 = 2.1 * 2 = 2.Example 3:
Input: n = 4, brightness = 2, intervals = [[1,3],[2,4]]
Output: 4
Explanation:
[1,4], which is 4.1 * 4 = 4.Constraints:
1 <= n <= 1061 <= brightness <= n1 <= intervals.length <= 105intervals[i] == [starti, endi]0 <= starti <= endi <= 109Loading editor...
5 5 [[6,12]]