DrawCode Practice Problem

Best Time to Buy and Sell Stock

You are given an array `prices` where `prices[i]` is the price of a stock on day `i`. Return the maximum profit from one buy and one sell. If no profit is possible, return 0.

Examples

Input

prices = [7,1,5,3,6,4]

Output

5

Buy day 1 (1), sell day 4 (6), profit = 5.

Input

prices = [7,6,4,3,1]

Output

0

Constraints


Interactive Visualizer Workspace

Explore step-by-step interactive animations, memory state tracking, and live multi-language execution in DrawCode.

Launch Interactive Visualizer