Hudson River TradingOA #7
Future Stock Prices
Estimated HardStatement and editorial — judging is being prepared
Topics (AI-labelled)Stock TradingState MachinesStrings
Given an unordered list of future stock prices, what is the maximum amount of profit that you could generate from a starting amount of $1,000.00
Rules:
You can trade fractional shares (e.g. if there were shares for $400.00, you could buy/sell 2.5 of them for $1,000.00)
All trades occur instantaneously and do not incur any transaction costs.
Shares may only be bought/sold 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]
Function Description
Complete the function calculateMaxProfit in the editor.
calculateMaxProfit has the following parameter:
String[] stockPrices: an array of stock price information Returns int: the maximum profit rounded to the nearest dollar
Editorial
Loading solution…