using System;
public class Program
{
public static void Main()
int[] prices = new int[] {1, 2, 3};
var profit = maximumProfit(prices);
Console.WriteLine("Maximum profit is " + profit.ToString());
}
public static int maximumProfit(int[] prices)
return 0;
/*
You are given an array of historic prices where prices[i] is the price of a given stock on the ith day.
You want to find the maximum profit that could have been made from trading this stock.
For each day, you can either buy, sell, or do nothing.
You can buy and sell multiple times, but cannot hold more than 1 stock.
Return the maximum profit you can achieve from these transactions. If you cannot achieve any profit, return 0.
Example 1: Input: prices = [1,2,3,4,5], Output: 4
Explanation: Buy on day 1 (price = 1), and sell on day 5 (price = 5)
Example 2: Input: prices = [7,1,5,3,5,6,4], Output: 7
Explanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.
Buy again on day 4 (price = 3) and sell on day 6 (price = 6), profit = 6-3 = 3.
Total profit is 4 + 3 = 7.
Note that buying on day 3 and selling on day 1 is not allowed because you must buy before you sell.
Example 3: Input: prices = [7,6,4,3,1], Output: 0
Explanation: In this case, no transactions are done and the max profit = 0.
Constraints:
1 <= prices.length <= 1e5
0 <= prices[i] <= 1e4
*/