Embercode
✕
ArraysCoding problems

Arrays: coding problems

Write a program that reads the input and prints the answer. Run checks it against every test, including hidden ones.

0 of 7 solved

  • A shop tracks the price of one product on each day. A trader may buy on one day and sell on a later day. Find the largest profit the trader can make. If no profit is possible, print 0.

    **Constraints:** 1 <= n <= 100000 and 0 <= price <= 10^9.

    Input. First line n. Second line n integers, the price on each day from day 0.

    Output. One integer: the largest profit, or 0.

    Example 1 input

    6
    7 1 5 3 6 4
    

    Output

    5
    

    Example 2 input

    4
    9 7 4 3
    

    Output

    0