Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2. Hindsight is 20/20 when it comes to trading stocks. Suppose you're given an array P[1, ...,n], where P[i] is the price of a certain
2. Hindsight is 20/20 when it comes to trading stocks. Suppose you're given an array P[1, ...,n], where P[i] is the price of a certain stock (e.g., GME), on day i. The goal is to find the best days to buy and sell in order to maximize your profit. The return value of your algorithms should be the profit per share. You may assume that you're only buying and selling one share of the stock, the price doesn't change during the day, and that the share needs to be bought before it is sold (no selling short like those hedge funds). In other words, you are trying to maximize P[j] P[i] over all pairs of indices i and j, where i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started