public static void Main()
double[] stock_prices_yesterday;
stock_prices_yesterday = new double[10]
{19.89, 19.99, 20.00, 26.00, 29.00, 18.00, 17.00, 19.75, 19.50, 19.30};
Console.WriteLine(GetMaxProfit(stock_prices_yesterday));
public static double GetMaxProfit(double[] stock_prices_yesterday)
if (stock_prices_yesterday.Length < 2)
return stock_prices_yesterday[0];
double minPrice = stock_prices_yesterday[0];
double maxProfit = stock_prices_yesterday[1] - stock_prices_yesterday[0];
double potentialProfit = 0;
for(int i = 0; i<= stock_prices_yesterday.Length-1; i++)
currentPrice = stock_prices_yesterday[i];
potentialProfit = currentPrice - minPrice;
maxProfit = System.Math.Max(maxProfit, potentialProfit);
minPrice = System.Math.Max(minPrice, currentPrice);
Console.WriteLine("---------------------------------");
Console.WriteLine("min_price" + minPrice);
Console.WriteLine("max_profit" + maxProfit);
Console.WriteLine("current_price" + currentPrice);
Console.WriteLine("potential_profit" + potentialProfit);
Console.WriteLine("---------------------------------");