Company: PLUTUS_RESEARCH_IITR
Difficulty: medium
Best Time to Buy and Sell Stock A trading desk keeps the closing price of one share for n consecutive sessions. The price of session i is prices[i] . You are allowed to buy that share on exactly one session and to sell it again on a later session. You may also decide not to trade at all. Buying and selling on the same session is not a trade. Report the largest amount sell price - buy price that such a single trade can earn. If every choice would lose money, report 0 , because doing nothing is always allowed. Implement maxProfit(prices) ; it returns that largest profit. Input Format The first line holds the integer n , the number of sessions. The second line holds n integers, prices[0] to prices[n - 1] , separated by spaces. Output Format Print one integer, the largest profit a single trade can earn, or 0 when no trade earns anything. Constraints 1 <= n <= 3000 (inferred -- the source capture allows 100000 sessions, which would push a single input past the judge's 200,000 byte std