Skip to content

Instantly share code, notes, and snippets.

@Aurea-Li
Last active February 21, 2019 18:31
Show Gist options
  • Save Aurea-Li/a975f267a572884d945604a90367fc12 to your computer and use it in GitHub Desktop.
Save Aurea-Li/a975f267a572884d945604a90367fc12 to your computer and use it in GitHub Desktop.
CS Fun Interview Questions
# What is time and space complexity of algorithm?
# Unsure how to only keep track of one integer value instead of saving an array of minimum waste values.
def minimum_waste(bottles, potion):
# sort from greatest to least
bottles.sort(reverse = True)
w = []
recurse_minimum_waste(w, bottles, potion, bottles[0])
return min(w)
def recurse_minimum_waste(w, bottles, potion, current_bottle):
# base case
if potion <= current_bottle:
w.append(current_bottle - potion)
return
# recurse case
else:
for i in range(len(bottles)):
recurse_minimum_waste(w, bottles[i:], potion - bottles[i], bottles[i])
print(minimum_waste([30, 20, 70, 100], 175))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment