-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTandemBicycle.py
More file actions
23 lines (19 loc) · 849 Bytes
/
TandemBicycle.py
File metadata and controls
23 lines (19 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'''
Tandem Bicycle
Write a function that takes in two arrays, representing the speeds
of blue shirt and red shirt riders as well as an argument 'fastest'
that will determine whether you calculate the slowest or fastest
possible speeds. Each blue shirt rider will be paired with a red
shirt rider. Return the slowest or fastest summed speed of all the
riders depends on if fastest is set to true or false
Time: O(NlogN) + O(MlogM), where N and M = red/blue shirt riders
Space: O(1)
'''
def tandemBicycle(redShirtSpeeds, blueShirtSpeeds, fastest):
sumOfSpeeds = 0
redShirtSpeeds.sort()
if fastest: blueShirtSpeeds.sort(reverse=True)
else: blueShirtSpeeds.sort()
for i in range(len(redShirtSpeeds)):
sumOfSpeeds += max(redShirtSpeeds[i],blueShirtSpeeds[i])
return sumOfSpeeds