public static void Main(string[] args)
int[] prices = { 20, 150, 10, 200, 5, 25, 400 };
Console.WriteLine(MaxProfit(prices));
public static int MaxProfit(int[] sharePrices)
if (sharePrices.Length < 1)
int lowBuy = sharePrices[0];
for (int i = 1; i < sharePrices.Length; i++)
if (sharePrices[i] < lowBuy)
else if (sharePrices[i] - lowBuy > maxProfit)
maxProfit = sharePrices[i] - lowBuy;