java.lang.Object
g1901_2000.s1921_eliminate_maximum_number_of_monsters.Solution

public class Solution extends Object
1921 - Eliminate Maximum Number of Monsters.<p>Medium</p> <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></code> monster from the city.</p> <p>The monsters walk toward the city at a <strong>constant</strong> speed. The speed of each monster is given to you in an integer array <code>speed</code> of size <code>n</code>, where <code>speed[i]</code> is the speed of the <code>i<sup>th</sup></code> monster in kilometers per minute.</p> <p>You have a weapon that, once fully charged, can eliminate a <strong>single</strong> monster. However, the weapon takes <strong>one minute</strong> to charge.The weapon is fully charged at the very start.</p> <p>You lose when any monster reaches your city. If a monster reaches the city at the exact moment the weapon is fully charged, it counts as a <strong>loss</strong> , and the game ends before you can use your weapon.</p> <p>Return <em>the <strong>maximum</strong> number of monsters that you can eliminate before you lose, or</em> <code>n</code> <em>if you can eliminate all the monsters before they reach the city.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> dist = [1,3,4], speed = [1,1,1]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong></p> <p>In the beginning, the distances of the monsters are [1,3,4]. You eliminate the first monster.</p> <p>After a minute, the distances of the monsters are [X,2,3]. You eliminate the second monster.</p> <p>After a minute, the distances of the monsters are [X,X,2]. You eliminate the thrid monster.</p> <p>All 3 monsters can be eliminated.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> dist = [1,1,2,3], speed = [1,1,1,1]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong></p> <p>In the beginning, the distances of the monsters are [1,1,2,3]. You eliminate the first monster.</p> <p>After a minute, the distances of the monsters are [X,0,1,2], so you lose. You can only eliminate 1 monster.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> dist = [3,2,4], speed = [5,3,2]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong></p> <p>In the beginning, the distances of the monsters are [3,2,4]. You eliminate the first monster.</p> <p>After a minute, the distances of the monsters are [X,0,2], so you lose. You can only eliminate 1 monster.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == dist.length == speed.length</code></li> <li><code>1 <= n <= 10<sup>5</sup></code></li> <li><code>1 <= dist[i], speed[i] <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • eliminateMaximum

      public int eliminateMaximum(int[] dist, int[] speed)