-
Notifications
You must be signed in to change notification settings - Fork 4
/
Codility.py
31 lines (23 loc) · 927 Bytes
/
Codility.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
__author__ = 'deepika'
def shortestWinterLength(listofTemperatures):
if len(listofTemperatures) == 0 :
return 0
length = len(listofTemperatures)
winter_high = listofTemperatures[0]
overall_high = listofTemperatures[0]
winter_length = 0
# Get max in the left array
for temperature in listofTemperatures:
if temperature <= winter_high :
winter_high = overall_high
elif temperature > overall_high :
overall_high = temperature
print("winter_high = " + str(winter_high) + " overall_high = " + str(overall_high))
# count all the values which are less than max in left array
for temperature in listofTemperatures :
if temperature <= winter_high :
winter_length += 1
# total length of the left array
print (winter_length)
shortestWinterLength([5, -2, 3, 8, 6])
shortestWinterLength([-5, -5, -5, -42, 6, 12])