Can anyone point out (line 29 - commented out) why do we get “Runtime Error” if I do a br.close (closing the BufferedReader). I thought closing the BufferedReader was a good practice.
Once I commented it out, the submission was accepted.
I wanted to know what would be the output for the following test case
8 4 6 5
Would it be 3 or 2?
I read abhinav1592’s solution and it gives the answer as 2
I think the answer should be 3 because in the problem it is clearly mentioned that cars cannot overtake as the track is not wide enough.
So the first car is travelling at max speed. The second one is also travelling at max speed since its speed is less than 8. The third one is not at max speed. The fourth one is travelling at max speed.
We just have to compare the speeds of consecutive cars right??? and not with all the cars… as cars cannot overtake… Please help me understand the problem…
Sir, may i know why this is giving worng answer? thanks
#include<stdio.h>
int main(){
int t,n,count;
long long int a[10000];
scanf("%d",&t);
while(t–){
count=1;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
if(a[i]<=a[i-1] &&i !=0){
count++;
}
}
printf("%d\n",count);
}
}
“”“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.