public static void Main()
Console.WriteLine($"[7,1,5,3,6,4] = {SellAndBuy([7,1,5,3,6,4])} = Expect[5]");
Console.WriteLine($"[7,1,5,3,6,4,10] = {SellAndBuy([7,1,5,3,6,4,10])} = Expect[9]");
Console.WriteLine($"[7,1,15,3,6,4,10] = {SellAndBuy([7,1,15,3,6,4,10])} = Expect[14]");
Console.WriteLine($"[] = {SellAndBuy([])} = Expect[0]");
Console.WriteLine($"[1] = {SellAndBuy([1])} = Expect[0]");
Console.WriteLine($"[2,1] = {SellAndBuy([2,1])} = Expect[0]");
Console.WriteLine($"[2,10] = {SellAndBuy([2,10])} = Expect[8]");
private static int SellAndBuy(int[] array)
for(var left = 0; left < l - 1; left++)
for(var right = left; right < l; right++)
res = int.Max(res, array[right] - array[left]);