Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Eliminate Maximum Number of Monsters

XPChallenge Points: 20
levelLevel: Medium

You are defending a city from n monsters approaching it.
Each monster starts at a certain distance, given in the array dist, and they all move toward the city at speeds provided in the array speed, where speed[i] is the speed of monster i.

You have a weapon that can destroy one monster per minute, and it is ready at the start. After each use, it needs one full minute to charge again.

If a monster reaches the city at any time, even exactly when your weapon gets recharged, you immediately lose.

Your task is to find out how many monsters you can destroy before losing.
Return the maximum possible count, or return n if you can destroy all of them.

Example 1:

Input: dist = [2, 6, 3], speed = [1, 2, 1]

Output: 2

Explanation:

Distances decrease each minute. You destroy monsters before any reaches the city. You manage to destroy 2 before one arrives.

Example 2:

Input: dist = [4, 2, 5], speed = [2, 1, 2]

Output: 1

Explanation:

One monster reaches too quickly, allowing only the first monster to be eliminated.

Example 3:

Input: dist = [10, 8], speed = [1, 2]

Output: 2

Explanation:

Both monsters take enough time to reach the city, so you eliminate both.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result