Question: I tried to do a dp solution for this question but it is too slow or I could not memoize it properly Anyone know if
I tried to do a dp solution for this question but it is too slow or I could not memoize it properly Anyone know if this could be solved more optimally Here is the problem Problem Statement Given an unordered list of future stock prices what is the maximum amount of profit that you could generate from a starting amount of 100000 Rules You can trade fractional shares eg if there were shares for 40000 you could buysell 25 of them for 100000 All trades occur instantaneously and do not incur any transaction costs Shares may only be boughtsold on a date that you have a known price Short selling is not allowed You do not need to have a position at all times at any time if you cannot identify a profitable trade you do not have to trade Round final answer to nearest dollar Do not assume input tuple will be sorted in any manner Future prices will be given as a list in the following format Stock Date Price Example 1 Input CSCO 101820244189 AMZN 10102024 11367 AMZN 10182024 1205 CSCO 101020244312 Solution Buy 8797 AMZN 11367 on 10102024 and sell 1205 on 10182024 Profit 60 Example 2 Input IBM 12012023 13205 IBM 1203202313519 IBM 12182023 13407 AAPL 1201202318719 AAPL 1204202316433 AAPL 1220202318094 AAPL 1221202317965 GOOG 12012023 11641 GOOG 12072023 11136 GOOG 12192023 11219 Solution Buy 7573 IBM 13205 on 1212023 and sell 13519 on 1232023 Buy 6230 AAPL on 1242023 16433 and sell on 12202023 18094 Profit 127
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
