Skip to content

Instantly share code, notes, and snippets.

@prasadwrites
Last active July 7, 2023 17:23
Show Gist options
  • Save prasadwrites/633aeb780a5c01f12a0330e2a04efdf2 to your computer and use it in GitHub Desktop.
Save prasadwrites/633aeb780a5c01f12a0330e2a04efdf2 to your computer and use it in GitHub Desktop.
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