The Chain Reaction

You are given n beacons placed on a number line.

Each beacon is described by: beacons[i] = [positioni, poweri]

When beacon i is activated: It destroys all beacons to its left whose distance ≤ poweri

Important rules:

  • Beacons are activated from right → left
  • If a beacon is destroyed earlier, it cannot be activated
  • You are allowed to add one new beacon to the far right
  • That beacon activates first

Your task is to Choose the position and power of the new beacon so that: minimum number of existing beacons are destroyed and Return that minimum.

Example 1:

Input : n = 1 , beacons = [[5,10]]

Output : 0

Explanation: New beacon can be placed with power 0.

Example 2:

Input : n = 4 , beacons = [[1,100], [2,100], [3,100], [4,100]]

Output: 3

Explanation: When activating from right, the first beacon destroys all others.

Now Your Turn!

Pick the correct output for the given input

Input : n = 6 , beacons = [[1,1], [3,1], [5,1], [7,1], [9,1], [11,1]]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 ≤ n ≤ 100 000
  • 0 ≤ positioni ≤ 1 000 000, 1 ≤ poweri  ≤ 1 000 000

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
// --- IDE Code ---
class Solution {
public:
int minBeaconsLost(vector<vector<int>>& beacons) {
// Write your code here
return 0;
}
};
Test Case

Input:

Beacons