go: add «2873. Maximum Value of an Ordered Triplet I»

URL:	https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-i/
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2025-04-02 16:11:33 +02:00
parent 5c40a25702
commit b6c2e213a1
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -0,0 +1,14 @@
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
}