Last active
July 7, 2023 17:23
-
-
Save prasadwrites/633aeb780a5c01f12a0330e2a04efdf2 to your computer and use it in GitHub Desktop.
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
def maxProfit(arr): | |
max_profit = 0 | |
diff = 0 | |
mlen = len(arr) | |
for i in range(mlen): | |
for j in range( i+1 ,mlen): | |
if arr[i] < arr[j]: | |
diff = arr[j] - arr[i] | |
if max_profit < diff: | |
max_profit = diff | |
return max_profit | |
arr = [0, 6, 10, 3, 2, 80, -1, 10, 1] | |
print(maxProfit(arr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment