Skip to content
CampusEduX

Best Time to Buy and Sell Stock

Easyjavapythonccppjavascript

Given daily stock prices, choose one day to buy and a later day to sell so that the profit is as large as possible.

Input Format

The first line contains an integer N. The second line contains N space-separated integers, where the i-th value is the price on day i.

Output Format

Print the maximum possible profit, or 0 if no profit can be made.

Related Problems

  • Find the Largest Element
    Easy · java, python, c, cpp, javascript
    Solve Problem
  • Find the Smallest Element
    Easy · java, python, c, cpp, javascript
    Solve Problem
  • Find the Second Largest Element
    Easy · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...