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.
If some one is looking for a go solution with quick sort method, here is mine (working for all size of array) :
funcminiMaxSum(arr[]int32){// Sort array with Quick Sort methodvarsortArrayfunc(arrSort[]int32)[]int32sortArray=func(arrToSort[]int32)[]int32{iflen(arrToSort)<=1{returnarrToSort}pivot:=arrToSort[len(arrToSort)-1]arrToSort=arrToSort[:len(arrToSort)-1]varsmallerArr,biggerArr[]int32for_,v:=rangearrToSort{ifv<pivot{smallerArr=append(smallerArr,v)}else{biggerArr=append(biggerArr,v)}}smallerArr=append(sortArray(smallerArr),pivot)returnappend(smallerArr,sortArray(biggerArr)...)}arrSorted:=sortArray(arr)// Calcule Minimun and Maximum varminSum,maxSumint64fori,v:=rangearrSorted{ifi>=1{maxSum=maxSum+int64(v)}ifi<=len(arrSorted)-2{minSum=minSum+int64(v)}}fmt.Printf("%d %d",minSum,maxSum)}
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 →
If some one is looking for a go solution with quick sort method, here is mine (working for all size of array) :