Tag: hackerrank
-
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 :=…
-

Min Max Sum from hackerrank on C++
Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers. Full question is over here:hackerrank Working solution #include <bits/stdc++.h> using namespace std; void miniMaxSum(vector <int> arr)…