Go R1 Day 18
tech development 100DaysOfCode golang microblog puzzles algorithms
Day 18 of 100
progress
Hackerrank challenge “Sales by Match”
Code
// Hackerrank submission for https://www.hackerrank.com/challenges/sock-merchant/submissions/code/193045923
// Complete the sockMerchant function below.
func sockMerchant(n int, ar []int) int {
// possiblePairs := int(math.Floor(float64(n) / 2))
sort.Slice(ar, func(i, j int) bool { return ar[i] < ar[j] })
// sort.Sort(byValue(ar))
var currentPairMatched int = 0
// size := len(ar)
for i := 0; i < len(ar)-1; i++ {
if ar[i] == ar[i+1] {
fmt.Sprintf("Matched pair: %v with %v", ar[i], ar[i+1])
currentPairMatched++
i++
if i >= len(ar){
break
}
}
}
//return int(currentPairMatched)
// fmt.Sprintf("possible pairs: %f",possiblePairs)
// fmt.Printf("%s",currentPairMatched)
return int(currentPairMatched)
}