Tap here to switch tabs
Problem
Submissions

Problem: Count Positions on Street With Required Brightness

Try to solve the Count Positions on Street With Required Brightness problem.

Statement

You are given an integer n representing a street with positions numbered from 00 to n −1- 1.

You are also given a 2D integer array lights, where lights[i] =[positioni,rangei]= [\text{position}_i, \text{range}_i] indicates that there is a street lamp at position positioni\text{position}_i that illuminates the range [max⁡(0,positioni−rangei),min⁡(n−1,positioni+rangei)][\max(0, \text{position}_i - \text{range}_i), \min(n - 1, \text{position}_i + \text{range}_i)] (inclusive).

Additionally, you are given a 0-indexed integer array requirement of length n, where requirement[i] represents the minimum brightness required at position i. The brightness of position i is defined as the total number of street lamps that illuminate it.

Return the total number of positions i for which the brightness at position i is at least requirement[i].

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq lights.length ≤105\leq 10^5

  • 0≤positioni<0 \leq \text{position}_i < n

  • 0≤rangei≤1050 \leq \text{range}_i \leq 10^5

  • requirement.length ==== n

  • 0≤0 \leq requirement[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Positions on Street With Required Brightness

Try to solve the Count Positions on Street With Required Brightness problem.

Statement

You are given an integer n representing a street with positions numbered from 00 to n −1- 1.

You are also given a 2D integer array lights, where lights[i] =[positioni,rangei]= [\text{position}_i, \text{range}_i] indicates that there is a street lamp at position positioni\text{position}_i that illuminates the range [max⁡(0,positioni−rangei),min⁡(n−1,positioni+rangei)][\max(0, \text{position}_i - \text{range}_i), \min(n - 1, \text{position}_i + \text{range}_i)] (inclusive).

Additionally, you are given a 0-indexed integer array requirement of length n, where requirement[i] represents the minimum brightness required at position i. The brightness of position i is defined as the total number of street lamps that illuminate it.

Return the total number of positions i for which the brightness at position i is at least requirement[i].

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq lights.length ≤105\leq 10^5

  • 0≤positioni<0 \leq \text{position}_i < n

  • 0≤rangei≤1050 \leq \text{range}_i \leq 10^5

  • requirement.length ==== n

  • 0≤0 \leq requirement[i] ≤105\leq 10^5