FastPrepMaximum Planes Destroyed Before Landing

Maximum Planes Destroyed Before Landing

Agoda logoAgoda● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

There are n hostile planes. Plane i starts at positive height heights[i] and descends by descent[i] height units per minute.

At minute 0, and then once at the start of every following minute, you may destroy one plane. If any remaining plane has reached ground level at or before that minute, the defense ends before you can fire. Return the maximum number of planes you can destroy.

Function

maximumPlanesDestroyed(heights: int[], descent: int[]) → int

Examples

Example 1

heights = [1,3,4]descent = [1,1,1]return = 3

The landing deadlines are minutes 1, 3, and 4, so all three can be destroyed at minutes 0, 1, and 2.

Example 2

heights = [1,1,2]descent = [1,1,1]return = 1

After one shot at minute 0, another plane reaches ground at minute 1.

Constraints

  • 1 <= heights.length == descent.length <= 100000.
  • 1 <= heights[i], descent[i] <= 10^9.

More Agoda problems

See Agoda hiring insights
public int maximumPlanesDestroyed(int[] heights, int[] descent) {
    // Destroy one plane per minute before any remaining plane lands.
}
heights[1,3,4]
descent[1,1,1]
expected3
Checking account…