Skip to content

Commit b755fd5

Browse files
committed
DSA learning
1 parent b575b19 commit b755fd5

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
Problem statement: https://www.codechef.com/LRNDSA01/problems/CARVANS
3+
"""
4+
5+
def calculate(n, max_speeds):
6+
max_speed_count = 0
7+
lowest_so_far = -1
8+
for speed in max_speeds:
9+
if lowest_so_far == -1:
10+
lowest_so_far = speed
11+
max_speed_count += 1
12+
continue
13+
if speed <= lowest_so_far: # cars having speed eqauls to or lesser than the lowest speed so far, are moving at their max speed.
14+
lowest_so_far = speed
15+
max_speed_count += 1
16+
return max_speed_count
17+
18+
19+
if __name__ == '__main__':
20+
T = int(input()) # input number of test cases.
21+
22+
for i in range(T):
23+
N = int(input()) # enter number of cars
24+
max_car_speeds = list(map(int, input().split()))
25+
res = calculate(N, max_car_speeds)
26+
print(res)
27+
28+
29+

0 commit comments

Comments
 (0)