Tag: go
-
Minimum absolute difference in an array with Go
Problem url: https://www.hackerrank.com/challenges/minimum-absolute-difference-in-an-array/problem Solution: Results are generated in O(n)*log(n) since we are sorting the array first. We can transfer sorted array and compare each number with the next find to find the smallest difference. func minimumAbsoluteDifference(arr []int32) int32 { var f foo f = arr temp := Abs(f[0] – f[1]) sort.Sort(f) fmt.Println(f) for i:=0; i…
-
Migratory Birds problem from Hackerrank with Go
Problem url: https://www.hackerrank.com/challenges/migratory-birds/problem Solution: Results are generated in O(1) while traversing an array. We need to keep track of the largest value and keep a record of the smallest key. func migratoryBirds(arr []int32) int32 { //key value m := make(map[int32]int32) largest := int32(0) largestKey := int32(0) for _, key := range arr { c :=…