---
# System prepended metadata

title: Untitled

---

Given an array of stock prices for a day, where prices[i] is the price of the stock at time i, write a function that returns the maximum amount of money one could make in a day if he buys and sells at most once.

// Test cases
/*
[7,4,4,2,0] -> 0
[8, 4, 0, 3, 4] -> 4

[9,2,3] -> 1

[5,6,7,1,2] -> 2
[+1, +1, -6, +1]
*/


minBuy = infinity;
maxProfit = 0;

for (i = 0; i < prices.length; i++) {
    
}


function stockPrices(prices) {
maxProfit = 0;

for (i = 0; i < prices.length; i++) {
    for (j = i; j < prices.length; j++) {
        maxProfit = Max(maxProfit, prices[j] - prices[i]);
    }
}
return maxProfit;
}


/////
myMax = prices.Max();
myMin = prices.Min();

profit = myMax - myMin;
return profit;



var isNonDecreasing = function(priceArray[]) {
    for (i = 1; i < priceArray.length; i++) {
        if (priceArray[i] <= priceArray[i - 1]) {
            // do nothing
        } else {
            return false;
        }
    }
    return true;
}