This notebook was prepared by Donne Martin. Source and license info is on GitHub.
Refer to the Solution Notebook. If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start.
class Solution(object):
def find_max_profit(self, prices):
# TODO: Implement me
pass
The following unit test is expected to fail until you solve the challenge.
# %load test_max_profit.py
import unittest
class TestMaxProfit(unittest.TestCase):
def test_max_profit(self):
solution = Solution()
self.assertRaises(TypeError, solution.find_max_profit, None)
self.assertRaises(ValueError, solution.find_max_profit, [])
self.assertEqual(solution.find_max_profit([8, 5, 3, 2, 1]), -1)
self.assertEqual(solution.find_max_profit([5, 3, 7, 4, 2, 6, 9]), 7)
print('Success: test_max_profit')
def main():
test = TestMaxProfit()
test.test_max_profit()
if __name__ == '__main__':
main()
Review the Solution Notebook for a discussion on algorithms and code solutions.