go: add «2874. Maximum Value of an Ordered Triplet II»

URL:	https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-ii/
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2025-04-03 18:29:09 +02:00
parent b6c2e213a1
commit b8bdec306c
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -0,0 +1,13 @@
package main
func maximumTripletValue(nums []int) int64 {
var maxValue, imax, dmax int64 = 0, 0, 0
for _, x := range nums {
num := int64(x)
maxValue = max(maxValue, dmax*num)
dmax = max(dmax, imax-num)
imax = max(imax, num)
}
return maxValue
}