1921. Eliminate Maximum Number of Monsters

T: O(nlogn)
S: O(n)
```java
class Solution {
    public int eliminateMaximum(int[] dist, int[] speed) {
        int[] arriaveTimes = new int[dist.length];
        for (int i = 0; i < dist.length; i++) {
            int time = dist[i]/speed[i];
            arriaveTimes[i] = (dist[i]%speed[i] != 0) ?  time + 1 : time;
        }
        Arrays.sort(arriaveTimes); // 1,1,2
        int count = 1;
        for (int i = 1; i < arriaveTimes.length; i++) {
            if (arriaveTimes[i] <= i) { //arriveTime <= current time(i), means arriving!
                return count;
            }
            count++;
        }
        return count;
    }
}

/**
T: O(nlogn)
S: O(n)

n is monster number

ans is 1~n

cal arrive time,
sort arrive time

then just test this round (time, after reload (1min))
is monster arrived or not

if arrived return count, not -> count++
 */
```

Last updated