Skip to content

Instantly share code, notes, and snippets.

@mrchocoborider
Last active September 6, 2018 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrchocoborider/aff6f532e1083a7d0e860862298a3f84 to your computer and use it in GitHub Desktop.
Save mrchocoborider/aff6f532e1083a7d0e860862298a3f84 to your computer and use it in GitHub Desktop.
Interviewcake.com algorithmic pattern practice #1, my solution.
#Set the max profit to -infinity, because if the first possible trade is a loss (negative #)
#we still want to keep track of it, and since we're checking if the potential profit is greater,
#-infinity is guaranteed to be smaller than any possible loss.
mp = float('-inf')
def get_max_profit(sp):
for i, s in enumerate(sp):
for j in range(i + 1, len(sp)):
p = sp[j] - sp[i]
if p > mp:
mp = p
return mp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment