Answers for "stock maximum profit"

0

stock maximum profit

function StockPicker(arr) { 
    let lissf = arr[0]
    let profit = -1
    for(let i = 1; i < arr.length; i++) {
        if(arr[i] > lissf) {
            profit = Math.max(profit, arr[i] - lissf)
        } else {
            lissf = arr[i]
        }
    }
    return profit
}
Posted by: Guest on June-30-2021

Browse Popular Code Answers by Language