“”“This approach works too ,and is faster than other appraoches mentioned above”""
“”“AC in one go”""
test=int(raw_input())
for _ in range(test):
N=int(raw_input())
count=1
arr=list()
arr=[int(i) for i in raw_input().split()]
for i in range(len(arr)-1):
if(arr[i+1]>arr[i]):
arr[i+1]=arr[i]
else:
count+=1
print count
if W==1 you still need to input speed of the only car of this test. Otherwise you consider its speed as a number of cars for the next test. Also while(–N) as well as while(–W) is wrong. By this you miss the last test case, last car respectively. Use while(N–) and while(W–) instead.
The third car also moves with speed 4 since it can not overtake the second car. So yes, we should compare only consecutive cars but the speed of each car may change.
@yellow_agony@fushar : kindly update the test-cases, as the code with normal string comparisons is also giving AC, e.g. the cars : [4 5 50 20 2 1] gives output as 4 as cars at maximum speed are [4 20 2 1], whereas ideally it should give output as 3 as cars at maximum speeds are [4 2 1]. So the code with string comparison should not run as the speed is integral/numerical comparison. Correct me if I am wrong
There is no need for array at all,
run a loop and keep track of min value as you read the input.
And the answer is how many times you read values less than or equal to current min. Thats It.