I am not getting this problem statement “CARVANS” …Can you please explain the given EXAMPLE in the problem so that I can solve it.
From the 2nd tc-
8 3 6
Let us suppose that the cars are numbered from 1 to N. So, the 1st car with maximum speed 8 enters the road. Since,no other car is ahead of it, it can move freely. So the count becomes 1.
Now, the second car with max speed 3 enters. Since, the speed of 2nd car(speed=3) is less than 1st car(speed=8), it too can move. So count becomes 2.
Now 3rd car enters the road. Its speed is 6. Since, no car can overtake any car ahead of it, the 3rd car is forced to reduce its speed since, the car ahead of it has speed 3.
So the total number of cars moving at their maximum speed is 2.
Same for 3rd tc-
4 5 1 2 3
1st car can move freely, count=1
2nd car cannot
3rd car can move, count=2
4th car cannot
5th car cannot
So total count=2
Thankyou sir…I got it !!
Sir…why I am getting a wrong answer …I m comparing the previous car with the new car coming.
public static void main(String args)
Scanner sc=new Scanner(System.in);
int arr=new int[n];
You should compare it with the minimum speeds of the previous cars.