diff --git a/go/minimum-difference-between-largest-and-smallest-value-in-three-moves.go b/go/minimum-difference-between-largest-and-smallest-value-in-three-moves.go new file mode 100644 index 0000000..50e34b4 --- /dev/null +++ b/go/minimum-difference-between-largest-and-smallest-value-in-three-moves.go @@ -0,0 +1,18 @@ +package main + +import "slices" + +func minDifference(nums []int) int { + if len(nums) <= 4 { + return 0 + } + + slices.Sort(nums) + + diff := nums[len(nums)-1] - nums[0] + for i := 0; i < 4; i++ { + diff = min(diff, nums[len(nums)-4+i]-nums[i]) + } + + return diff +}