Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 224
Good morning! Here's your coding interview problem for today.

This problem was asked by Amazon.

Given a sorted array, find the smallest positive integer that is not the sum of a subset of the array.

For example, for the input `[1, 2, 3, 10]`, you should return `7`.

Do this in O(N) time.

Pull request description:
Day224
Resolves #462.

Patch:
diff --git a/README.md b/README.md
index 5a4dc8b..7f50028 100644
--- a/README.md
+++ b/README.md
@@ -234,3 +234,4 @@ problems from
 * [Day 221](https://github.com/vaskoz/dailycodingproblem-go/issues/454)
 * [Day 222](https://github.com/vaskoz/dailycodingproblem-go/issues/458)
 * [Day 223](https://github.com/vaskoz/dailycodingproblem-go/issues/460)
+* [Day 224](https://github.com/vaskoz/dailycodingproblem-go/issues/462)
diff --git a/day224/problem.go b/day224/problem.go
new file mode 100644
index 0000000..1dae348
--- /dev/null
+++ b/day224/problem.go
@@ -0,0 +1,13 @@
+package day224
+
+// SmallestPositiveIntNotInSubsetSum returns the
+// smallest positive integer that is not the sum of a subset of the array,
+// given a sorted array.
+// Runs in O(N) time and O(1) space.
+func SmallestPositiveIntNotInSubsetSum(nums []int) int {
+	result := 1
+	for i := 0; i < len(nums) && nums[i] <= result; i++ {
+		result += nums[i]
+	}
+	return result
+}


Test patch:
diff --git a/day224/problem_test.go b/day224/problem_test.go
new file mode 100644
index 0000000..a8e6924
--- /dev/null
+++ b/day224/problem_test.go
@@ -0,0 +1,31 @@
+package day224
+
+import "testing"
+
+var testcases = []struct {
+	nums     []int
+	smallest int
+}{
+	{[]int{1, 2, 3, 10}, 7},
+	{[]int{1, 3, 4, 5}, 2},
+	{[]int{1, 2, 6, 10, 11, 15}, 4},
+	{[]int{1, 1, 1, 1}, 5},
+	{[]int{1, 1, 3, 4}, 10},
+}
+
+func TestSmallestPositiveIntNotInSubsetSum(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := SmallestPositiveIntNotInSubsetSum(tc.nums); result != tc.smallest {
+			t.Errorf("For %v, expected %v, got %v", tc.nums, tc.smallest, result)
+		}
+	}
+}
+
+func BenchmarkSmallestPositiveIntNotInSubsetSum(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			SmallestPositiveIntNotInSubsetSum(tc.nums)
+		}
+	}
+}