Leetcode Problem 1921. Eliminate Maximum Number of Monsters

1921. Eliminate Maximum Number of Monsters

Leetcode Solutions

Sort By Arrival Time

  1. Calculate the arrival time for each monster by dividing dist[i] by speed[i] and store the results in an array arrival.
  2. Sort the arrival array in ascending order.
  3. Initialize a counter ans to 0 to keep track of the number of monsters eliminated.
  4. Iterate over the sorted arrival array and for each index i, check if arrival[i] <= i.
    • If true, break the loop as we cannot eliminate this monster.
    • Otherwise, increment ans.
  5. Return the value of ans which represents the maximum number of monsters that can be eliminated.
UML Thumbnail

Heap Based Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...