id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

gaurav1780@gmail.com 04_lists > max_profits
prev  |  next  |  chance

Consider a list containing a stock's value over a certain number of days. Define a function that when passed this list, returns the maximum profit that could be made. For example, if the list is {10, 20, 70, 90, 30, 80}, buying the stock on day 1 (10) and selling on day 4 (90), and then buying it again on day 5 (30) and selling it on day 6 (80) would result in an overall profit of 130. maxProfit([10, 20, 70, 90, 30, 80]) → 130 maxProfit([100, 180, 260, 310, 40, 535, 695]) → 865 maxProfit([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) → 13


max_profits([10, 20, 70, 90, 30, 80]) → 130
max_profits([100, 180, 260, 310, 40, 535, 695]) → 865
max_profits([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) → 13

...Save, Compile, Run (ctrl-enter)

def max_profits(data):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 4 Post-solution available

Copyright Nick Parlante 2017 - privacy