using System.Collections.Generic;
public static void Main()
int[] stockPrices = { 10, 7, 5, 8,7, 11, 9 };
TradeMultiple(stockPrices);
public static void TradeOnce(int[] stockPrices)
var end = stockPrices.Length;
for (var i=0; i<end; i++) {
var currentPrice = stockPrices[i];
for(var j = i + 1; j <end; j++) {
var newprice = stockPrices[j];
if (currentPrice < newprice) {
var currentProfit = newprice -currentPrice;
if (currentProfit > maxProfit) {
maxProfit = currentProfit;
Console.WriteLine("If I trade once, maximum profit is: " + maxProfit);
public static void TradeMultiple(int[] stockPrices)
var end = stockPrices.Length;
for (var i=0; i<end; i++) {
var currentPrice = stockPrices[i];
minimum_price = stockPrices[0];
minimum_price = Math.Min(stockPrices[0], stockPrices[i]) ;
var profit = stockPrices[i] - minimum_price;
maxProfit = Math.Max(maxProfit, profit);
Console.WriteLine("If I trade multiple times, maximum profit is: " + maxProfit);