Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 390
Good morning! Here's your coding interview problem for today.

This problem was asked by Two Sigma.

You are given an unsorted list of 999,000 unique integers, each from 1 and 1,000,000. Find the missing 1000 numbers. What is the computational and space complexity of your solution?

Pull request description:
Day390
Resolves #783.

Patch:
diff --git a/README.md b/README.md
index d5a0b0b..4909e5f 100644
--- a/README.md
+++ b/README.md
@@ -382,4 +382,5 @@ problems from
 * [Day 384](https://github.com/vaskoz/dailycodingproblem-go/issues/776)
 * [Day 385](https://github.com/vaskoz/dailycodingproblem-go/issues/774)
 * [Day 386](https://github.com/vaskoz/dailycodingproblem-go/issues/778)
+* [Day 390](https://github.com/vaskoz/dailycodingproblem-go/issues/783)
 
diff --git a/day390/problem.go b/day390/problem.go
new file mode 100644
index 0000000..56ce768
--- /dev/null
+++ b/day390/problem.go
@@ -0,0 +1,22 @@
+package day390
+
+// MissingThousandInMillion returns the numbers missing
+// between 1 and 1 million.
+// Runs in O(N) time and space.
+func MissingThousandInMillion(nums []int) []int {
+	seen := make(map[int]struct{}, len(nums))
+
+	for _, n := range nums {
+		seen[n] = struct{}{}
+	}
+
+	ans := make([]int, 0, 1_000_000-len(seen)+1)
+
+	for n := 1; n <= 1_000_000; n++ {
+		if _, ok := seen[n]; !ok {
+			ans = append(ans, n)
+		}
+	}
+
+	return ans
+}


Test patch:
diff --git a/day390/problem_test.go b/day390/problem_test.go
new file mode 100644
index 0000000..d133828
--- /dev/null
+++ b/day390/problem_test.go
@@ -0,0 +1,53 @@
+package day390
+
+import (
+	"math/rand"
+	"reflect"
+	"testing"
+	"time"
+)
+
+func TestMissingThousandInMillion(t *testing.T) {
+	t.Parallel()
+
+	missing := []int{10_395, 25_011, 345_335, 565_332, 999_993}
+	input := setup(missing)
+
+	if res := MissingThousandInMillion(input); !reflect.DeepEqual(res, missing) {
+		t.Errorf("Expected %v, got %v", missing, res)
+	}
+}
+
+func BenchmarkMissingThousandInMillion(b *testing.B) {
+	missing := []int{25_011, 345_335, 565_332, 999_993, 10_395}
+	input := setup(missing)
+
+	for i := 0; i < b.N; i++ {
+		MissingThousandInMillion(input)
+	}
+}
+
+func setup(miss []int) []int {
+	r := rand.New(rand.NewSource(time.Now().UnixNano()))
+	ans := make([]int, 1_000_000-len(miss)+1)
+	missMap := make(map[int]struct{}, len(miss))
+
+	for _, n := range miss {
+		missMap[n] = struct{}{}
+	}
+
+	pos := 0
+
+	for n := 1; n <= 1_000_000; n++ {
+		if _, skip := missMap[n]; !skip {
+			ans[pos] = n
+			pos++
+		}
+	}
+
+	r.Shuffle(len(ans), func(i, j int) {
+		ans[i], ans[j] = ans[j], ans[i]
+	})
+
+	return ans
+}