cswork / OA打开练习工作台

Hudson River TradingOA #7

Future Stock Prices

估计困难评测数据准备中,可先阅读题面

考点(AI 标注)股票买卖状态机字符串

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