Top speed
There are N vehicles moving in the right direction on a narrow straight road. Each vehicle i has a top speed S: (the maximum speed with
which a vehicle move) associated with it. Each vehicle tries to move at its top speed but cannot attain the top speed because of the
congestion that has been created by vehicles ahead of them have a lesser speed. For every vehicle i, determine the minimum number of
vehicles it needs to overtake so that it attains its top speed assuming no other vehicle will overtake while computing the answer for the ith
vehicle.
Note: The Nth vehicle is the first in the line. A vehicle i can move at its top speed only when no other vehicles ahead of it are moving a
the top speed less than Si.
Input format
• First line: T denoting the number of test cases
• For each test case:
o First line: N denoting the number of vehicles on the road
o Next line: N space-separated integers representing the top speeds Si of the vehicle i
Output format
Print N space-separated integers and the ith integer representing the number of vehicles it needs to overtake to be able to move at
speed.
Constraints
1<T<3
I<N< 2 * 105
Answers
Answered by
0
Answer:
Explanation:
In this question we will first be looking at the no of vehicles and their top speeds. To overtake the each and every car. As we've two components hence we will take an array two inculcate both of the cars and speed.
As no language is specified we will just write the logical part of code snippet for sake of universal understanding.
printf("enter the no of cars");
scanf(%d,&n);
for(i=0;i<n;i++)
{
printf("car no%d", i+1);
printf("enter car speed");
scanf(%d,&s[i]);
}
printf("enter the car no to see position of car");
scanf(%d,& k);
for(i=0;i<k;i++)
{
printf("%d",i+1," ");
printf ("%d",s[i]);
}
printf ("minimum number of cars to overtake%d",n-k+1);
Similar questions