# airPlane invader question...help me to solve this question

N plane has a starting position above ground level and a speed at which it is descending.the player has a gun and can shoot the one plane each second.the game ends when a plane is allowed to land.determine maximum planes that can be prevented from landing.

example:- startHeight = [1,3,5,4,8] descentRate = [1,2,2,1,2] output to this example is 4

CONSTRAINTS :- 1≤n≤10^5, 1≤startHeight[i]≤10^9, 1≤descentRate≤10^5

One way to solve this problem:
Find the setps-to-crash Array as:
stepsArr = ceil(startHeight[i] / descentRate[i]);
And then Sort this Array. It will be easy to find the result now. I am sure there may be more optimal ways to solve this problem. Let me know if you for failing test-cases with this solution.

int maxPlanes(std::vector startHeight, std::vector descentRate)
{
int n = startHeight.size();
int plane_crashed = 0;
std::vector steps(n, 0);

``````for(int i=0; i<n; i++)
steps[i] = ceil((float)startHeight[i] / (float)descentRate[i]);

sort(steps.begin(), steps.end());
int j = 0;
for(int i=0; i<n; i++)
{
if(steps[i] > j)    // Shoot condition
j++;
}
return j;
``````

}

TC is O(nlogn) due to sorting
SC is O(n)