Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 211
Good morning! Here's your coding interview problem for today.

This problem was asked by Microsoft.

Given a string and a pattern, find the starting indices of all occurrences of the pattern in the string. For example, given the string "abracadabra" and the pattern "abr", you should return `[0, 7]`.

Pull request description:
Day211
Resolves #434.

Patch:
diff --git a/README.md b/README.md
index 57c9f14..0b8b1da 100644
--- a/README.md
+++ b/README.md
@@ -220,3 +220,4 @@ problems from
 * [Day 207](https://github.com/vaskoz/dailycodingproblem-go/issues/426)
 * [Day 208](https://github.com/vaskoz/dailycodingproblem-go/issues/427)
 * [Day 210](https://github.com/vaskoz/dailycodingproblem-go/issues/432)
+* [Day 211](https://github.com/vaskoz/dailycodingproblem-go/issues/434)
diff --git a/day211/problem.go b/day211/problem.go
new file mode 100644
index 0000000..2c07abf
--- /dev/null
+++ b/day211/problem.go
@@ -0,0 +1,24 @@
+package day211
+
+// StartingIndicies returns the starting indicies
+// of all occurrences of the pattern in the str.
+// Runs in O(N*K) time where N=len(str) and K=len(pattern).
+func StartingIndicies(str, pattern string) []int {
+	var result []int
+	for i := range str {
+		if len(pattern) > len(str)-i {
+			break
+		}
+		complete := true
+		for j, pr := range pattern {
+			if pr != rune(str[i+j]) {
+				complete = false
+				break
+			}
+		}
+		if complete {
+			result = append(result, i)
+		}
+	}
+	return result
+}


Test patch:
diff --git a/day211/problem_test.go b/day211/problem_test.go
new file mode 100644
index 0000000..849ac55
--- /dev/null
+++ b/day211/problem_test.go
@@ -0,0 +1,30 @@
+package day211
+
+import (
+	"reflect"
+	"testing"
+)
+
+var testcases = []struct {
+	str, pattern string
+	expected     []int
+}{
+	{"abracadabra", "abr", []int{0, 7}},
+}
+
+func TestStartingIndicies(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := StartingIndicies(tc.str, tc.pattern); !reflect.DeepEqual(result, tc.expected) {
+			t.Errorf("Expected %v, got %v", tc.expected, result)
+		}
+	}
+}
+
+func BenchmarkStartingIndicies(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			StartingIndicies(tc.str, tc.pattern)
+		}
+	}
+}