Skip to content

Commit 15a2452

Browse files
committed
Array Problems
1 parent 5f62c80 commit 15a2452

File tree

1 file changed

+58
-0
lines changed
  • CompetitiveProgramming/HackerEarth/DataStructures/Arrays

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Rash is known about his love for racing sports. He is an avid Formula 1 fan. He went to watch this year's Indian
2+
# Grand Prix at New Delhi. He noticed that one segment of the circuit was a long straight road. It was impossible for a
3+
# car to overtake other cars on this segment. Therefore, a car had to lower down its speed if there was a slower car in
4+
# front of it. While watching the race, Rash started to wonder how many cars were moving at their maximum speed.
5+
# Formally, you're given the maximum speed of N cars in the order they entered the long straight segment of the circuit.
6+
# Each car will prefers to move at its maximum speed. If that's not possible because of the front car being slow, it
7+
# might have to lower its speed. It still moves at the fastest possible speed while avoiding any collisions. For the
8+
# purpose of this problem, you can assume that the straight segment is infinitely long. Count the number of cars which
9+
# were moving at their maximum speed on the straight segment.
10+
#
11+
# Input
12+
#
13+
# The first line of the input contains a single integer T denoting the number of test cases to follow. Description of
14+
# each test case contains 2 lines. The first of these lines contain a single integer N, the number of cars. The second
15+
# line contains N space separated integers, denoting the maximum speed of the cars in the order they entered the long
16+
# straight segment.
17+
#
18+
# Output
19+
#
20+
# For each test case, output a single line containing the number of cars which were moving at their maximum speed on
21+
# the segment.
22+
#
23+
# Constraints
24+
#
25+
# 1≤T≤100
26+
# 1≤N≤105
27+
# 1≤speed≤109
28+
#
29+
# SAMPLE INPUT
30+
# 3
31+
# 1
32+
# 10
33+
# 3
34+
# 8 3 6
35+
# 5
36+
# 4 5 1 2 3
37+
#
38+
# SAMPLE OUTPUT
39+
# 1
40+
# 2
41+
# 2
42+
43+
testCases = int(input())
44+
for _ in range(testCases):
45+
n = input()
46+
myList = []
47+
count = 0
48+
check = input().split()
49+
if len(check) == 1:
50+
print(1)
51+
else:
52+
max = int(check[0])
53+
for i in range(1, len(check) - 1):
54+
if int(check[i]) <= max:
55+
count += 1
56+
max = int(check[i])
57+
58+
print(count + 1)

0 commit comments

Comments
 (0)