package main
import (
"fmt"
"math"
)
func max(x, y int) int {
if x > y {
return x
}
return y
}
func min(x, y int) int {
if x < y {
return x
}
return y
}
func maxArr(A []int) int {
maxVal1, maxVal2 := math.MinInt32, math.MinInt32
minVal1, minVal2 := math.MaxInt32, math.MaxInt32
for i := 0; i < len(A); i++ {
maxVal1 = max(maxVal1, A[i]+i)
minVal1 = min(minVal1, A[i]+i)
maxVal2 = max(maxVal2, A[i]-i)
minVal2 = min(minVal2, A[i]-i)
}
return max(maxVal1-minVal1, maxVal2-minVal2)
}
func main() {
fmt.Println(maxArr([]int{1, 3, -1}))
}
System Design for Beginners
A masterclass that helps early engineers and product managers become great at designing scalable systems.
180+ learners
Details →System Design Masterclass
A masterclass that helps you become great at designing scalable, fault-tolerant, and highly available systems.
1000+ learners
Details →Redis Internals
Learn internals of Redis by re-implementing some of the core features in Golang.
98+ learners
Details →