We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Problem is easy but 1 thing need to be considered is the number can be a big int.
Golang code
func miniMaxSum(arr []int32) {
// Write your code here
maxEle := arr[0]
minEle := arr[0]
sum := int64(0)
for i := 0; i < len(arr); i ++ {
sum += int64(arr[i])
if arr[i] > maxEle {
maxEle = arr[i]
} else {
if arr[i] < minEle {
minEle = arr[i]
}
}
}
fmt.Printf("%v %v", sum - int64(maxEle), sum - int64(minEle))
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Mini-Max Sum
You are viewing a single comment's thread. Return to all comments →
Problem is easy but 1 thing need to be considered is the number can be a big int. Golang code func miniMaxSum(arr []int32) { // Write your code here maxEle := arr[0] minEle := arr[0] sum := int64(0) for i := 0; i < len(arr); i ++ { sum += int64(arr[i]) if arr[i] > maxEle { maxEle = arr[i] } else { if arr[i] < minEle { minEle = arr[i] } } }
}