n drones are flying toward your base. distance[i] is how far the i-th drone starts from the base, in kilometers, and speed[i] is its constant speed in kilometers per minute.
You have a cannon that takes down one drone per shot. After each shot it needs exactly one minute to recharge, and it starts out charged at minute 0. So you can fire at minutes 0, 1, 2, ...
The moment any drone reaches the base, you lose. A drone that arrives exactly when the cannon finishes recharging also counts as a loss: there is no time left to fire.
Return the largest number of drones you can take down before losing, or n if you can take down all of them.distance=[4, 2, 6], speed=[2, 1, 2] → 3
The drones arrive after 2, 2 and 3 minutes. Shoot one at minute 0, another at minute 1 and the last at minute 2, each before anything lands.
distance=[3, 3, 3], speed=[3, 3, 1] → 1
Two drones arrive after exactly 1 minute. You shoot one right away, but the other lands at the very moment the cannon recharges, which counts as a loss. The answer is 1.
distance=[10], speed=[100] → 1
n = len(distance) = len(speed) ≤ 10⁵distance[i], speed[i] ≤ 10⁵distance=[4, 2, 6], speed=[2, 1, 2]
3
Run checks the first 3 tests in your browser. Submit checks all 130 tests on the server, hidden ones included.