Last active
September 6, 2018 02:58
-
-
Save mrchocoborider/aff6f532e1083a7d0e860862298a3f84 to your computer and use it in GitHub Desktop.
Interviewcake.com algorithmic pattern practice #1, my solution.
This file contains 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
#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