Tap here to switch tabs
Problem
Submissions

Problem: Minimum Lights to Illuminate a Road

Try to solve the Minimum Lights to Illuminate a Road problem.

Statement

You are given a 00 indexed integer array lights of length n, representing a road with n consecutive positions indexed from 00 to n −1- 1.

An existing light at index i has an illumination radius of lights[i]. When lights[i] > 0, it illuminates all positions from max⁡(0,i−\max(0, i - lights[i])) to min⁡(\min(n −1,i+- 1, i + lights[i])). If lights[i] = 0, there is no initial light active at index i.

You may install additional lights at any position. Each newly installed light has an illumination radius of 11, which illuminates all positions from max⁡(0,i−1)\max(0, i - 1) to min⁡(\min(n −1,i+1)- 1, i + 1).

Return the minimum number of additional lights needed so that every position from 00 to n −1- 1 is illuminated.

Constraints:

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

  • 0≤0 \leq lights[i] ≤\leq n

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Lights to Illuminate a Road

Try to solve the Minimum Lights to Illuminate a Road problem.

Statement

You are given a 00 indexed integer array lights of length n, representing a road with n consecutive positions indexed from 00 to n −1- 1.

An existing light at index i has an illumination radius of lights[i]. When lights[i] > 0, it illuminates all positions from max⁡(0,i−\max(0, i - lights[i])) to min⁡(\min(n −1,i+- 1, i + lights[i])). If lights[i] = 0, there is no initial light active at index i.

You may install additional lights at any position. Each newly installed light has an illumination radius of 11, which illuminates all positions from max⁡(0,i−1)\max(0, i - 1) to min⁡(\min(n −1,i+1)- 1, i + 1).

Return the minimum number of additional lights needed so that every position from 00 to n −1- 1 is illuminated.

Constraints:

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

  • 0≤0 \leq lights[i] ≤\leq n