Created
November 12, 2019 14:32
-
-
Save omar-yassin/56457d63be62d762ab987883c03df922 to your computer and use it in GitHub Desktop.
grrr #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python | |
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
k = 3 | |
team_size = 10 | |
new_team = [] | |
for team_iter in range(0, team_size): | |
# how many more team members | |
how_many_more = team_size - len(new_team) | |
if k >= how_many_more: | |
k = how_many_more | |
left_window = range(0, k) | |
right_window = range(len(arr)-k, len(arr)) | |
temp_largest = arr[0] | |
temp_largest_index = 0 | |
for index in left_window: | |
if arr[index] > temp_largest: | |
temp_largest = arr[index] | |
temp_largest_index = index | |
for index in right_window: | |
if arr[index] > temp_largest: | |
temp_largest = arr[index] | |
temp_largest_index = index | |
new_team.append(temp_largest) | |
del arr[temp_largest_index] | |
print(sum(new_team)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment