#MaxProfit
perhaps it’s like this?

function maxTheStock(prices) {
let maxProfit = 0, minPrice = Infinity;
for (let price of prices) {
minPrice = Math.min(minPrice, price);
maxProfit = Math.max(price - minPrice, maxProfit);
}
return maxProfit;
}
November 18, 2024 at 6:59 AM
Did best time to buy and sell stock from LeetCode in Haskell today. Felt good to get it down pretty quickly

I had written a Rust implementation similar to this a year ago, so this one fell into place nicely!
November 25, 2024 at 3:08 AM
Ich hätte nicht gedacht dass unsere Medien genauso... so... ich finde kein Wort dafür.... 🙄

So schwer ist der Denkprozess beim Lieferkettengesetz doch nicht?

Du willst fair behandelt werden? Ja denkst du andere nicht? 🙄

Ressourcenverschwendung zwecks MaxProfit ist nicht cool 🙄
November 14, 2025 at 8:47 PM
fun maxProfit(prices: IntArray): Int {
var currentMin = Int.MAX_VALUE
var maxProfit = 0
for (price in prices) {
currentMin = minOf(currentMin, price)
maxProfit = maxOf(maxProfit, price - currentMin)
}
return maxProfit
}
October 24, 2023 at 8:47 AM
maxProfit = Math.max(maxProfit, values[right] - values[left])
right++
}

left = right
}

return maxProfit
}

It has been a while since I’ve leetcoded and I’ve never written a function on my phone but I think that is close enough to working.
November 18, 2024 at 7:46 AM
Urban Freight Specialists | Smart Route Logistics

Receive load planning tailored for the nuances of inner-city deliveries.

smartroutelogistics.com

#UrbanDispatch #CityFreight #BoxTruckRoutes #DispatchExperts #MaxProfit
September 8, 2025 at 1:44 PM
const getMaxProfit = (values) => {
let maxProfit = 0
let left = 0
let right = 0

while (left < values.length) {
if (values[left] >= values[left + 1]) {
left++
}

right = left +1

while (right < values.length && values[right] > values[left]) {
November 18, 2024 at 7:46 AM
Затем для сравнения решаю на Котлине

Сначала пишу аналог решения на Uiua:

fun maxProfit(prices: IntArray): Int {
val runningMin = prices.runningReduce(::minOf)
val bestPerDay = prices.zip(runningMin, Int::minus)
return bestPerDay.max()
}
October 24, 2023 at 8:45 AM
With his incredible power of Hindsight, Hindsight Man has solved the stock market
March 5, 2026 at 5:53 AM