Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 111
Good morning! Here's your coding interview problem for today.

This problem was asked by Google.

Given a word W and a string S, find all starting indices in S which are anagrams of W.

For example, given that W is "ab", and S is "abxaba", return 0, 3, and 4.

Pull request:
Day111
Resolves #232.

Patch:
diff --git a/README.md b/README.md
index fc05bc0..a0e3c20 100644
--- a/README.md
+++ b/README.md
@@ -119,3 +119,4 @@ problems from
 * [Day 107](https://github.com/vaskoz/dailycodingproblem-go/issues/225)
 * [Day 108](https://github.com/vaskoz/dailycodingproblem-go/issues/227)
 * [Day 109](https://github.com/vaskoz/dailycodingproblem-go/issues/229)
+* [Day 111](https://github.com/vaskoz/dailycodingproblem-go/issues/232)
diff --git a/day111/problem.go b/day111/problem.go
new file mode 100644
index 0000000..ace9b37
--- /dev/null
+++ b/day111/problem.go
@@ -0,0 +1,24 @@
+package day111
+
+import "reflect"
+
+// StartIndicesAnagrams returns all the starting indices (0-based)
+// for the anagrams of W in the longer string S.
+// Runs in O(N*M) time where N is len(word) and M is len(str).
+func StartIndicesAnagrams(W string, S string) []int {
+	freq := make(map[rune]int)
+	for _, r := range W {
+		freq[r]++
+	}
+	var result []int
+	for i := range S {
+		sub := make(map[rune]int)
+		for j := i; j < len(S) && j < i+len(W); j++ {
+			sub[rune(S[j])]++
+		}
+		if reflect.DeepEqual(sub, freq) {
+			result = append(result, i)
+		}
+	}
+	return result
+}


Test patch:
diff --git a/day111/problem_test.go b/day111/problem_test.go
new file mode 100644
index 0000000..baa3e22
--- /dev/null
+++ b/day111/problem_test.go
@@ -0,0 +1,31 @@
+package day111
+
+import (
+	"reflect"
+	"testing"
+)
+
+var testcases = []struct {
+	W, S     string
+	expected []int
+}{
+	{"ab", "abxaba", []int{0, 3, 4}},
+	{"ba", "abxaba", []int{0, 3, 4}},
+	{"aabx", "abxaba", []int{0, 2}},
+}
+
+func TestStartIndicesAnagrams(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := StartIndicesAnagrams(tc.W, tc.S); !reflect.DeepEqual(tc.expected, result) {
+			t.Errorf("Expected %v got %v", tc.expected, result)
+		}
+	}
+}
+func BenchmarkStartIndicesAnagrams(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			StartIndicesAnagrams(tc.W, tc.S)
+		}
+	}
+}