Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python 3please Question 4: Maximum Profit fcr Stock (4 points) Suppose you have stock price history, and you are allowed to buy orly once and

python 3please
image text in transcribed
Question 4: Maximum Profit fcr Stock (4 points) Suppose you have stock price history, and you are allowed to buy orly once and sell only once. Write a function max_profit(prices) that finds the maximum profit you can make. There is no need to buy if no profit is possible. For example, if you have the prices 5, 10, 2, 11, 20], the maximum benefit would be buying at the price 2 and seling at the price 20 which equals to 18 In I : def max profit(prices): Your code here In [ ]: max-profit([10,22 , 17, 23, 15] 13

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started