Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 63
Good morning! Here's your coding interview problem for today.

This problem was asked by Microsoft.

Given a 2D matrix of characters and a target word, write a function that returns whether the word can be found in the matrix by going left-to-right, or up-to-down.

For example, given the following matrix:
```
[['F', 'A', 'C', 'I'],
 ['O', 'B', 'Q', 'P'],
 ['A', 'N', 'O', 'B'],
 ['M', 'A', 'S', 'S']]
```
and the target word 'FOAM', you should return true, since it's the leftmost column. Similarly, given the target word 'MASS', you should return true, since it's the last row.

Pull request description:
Day63
Resolves #136 .

Patch:
diff --git a/README.md b/README.md
index 4dc7196..fd6c7b0 100644
--- a/README.md
+++ b/README.md
@@ -73,3 +73,4 @@ problems from
 * [Day 60](https://github.com/vaskoz/dailycodingproblem-go/issues/130)
 * [Day 61](https://github.com/vaskoz/dailycodingproblem-go/issues/132)
 * [Day 62](https://github.com/vaskoz/dailycodingproblem-go/issues/134)
+* [Day 63](https://github.com/vaskoz/dailycodingproblem-go/issues/136)
diff --git a/day63/problem.go b/day63/problem.go
new file mode 100644
index 0000000..b1aeb66
--- /dev/null
+++ b/day63/problem.go
@@ -0,0 +1,34 @@
+package day63
+
+import "reflect"
+
+// FindWordLD answers if the target word is found in the puzzle.
+// Only searches left-to-right and top-to-bottom directions.
+// Brute force runtime where N=rows, M=cols, and K=len(target)
+// Runtime is O((N-K)*(M-K)*K)
+func FindWordLD(puzzle [][]rune, target []rune) bool {
+	coll := len(puzzle)
+	for row := range puzzle {
+		rowl := len(puzzle[row])
+		for col := range puzzle[row] {
+			if rowl-len(target)-col < 0 {
+				break
+			}
+			if reflect.DeepEqual(target, puzzle[row][col:col+len(target)]) {
+				return true
+			}
+			if coll-len(target)-row >= 0 {
+				vertical := true
+				for i := range target {
+					if puzzle[i+row][col] != target[i] {
+						vertical = false
+					}
+				}
+				if vertical {
+					return true
+				}
+			}
+		}
+	}
+	return false
+}


Test patch:
diff --git a/day63/problem_test.go b/day63/problem_test.go
new file mode 100644
index 0000000..30ff8ce
--- /dev/null
+++ b/day63/problem_test.go
@@ -0,0 +1,40 @@
+package day63
+
+import "testing"
+
+var testcases = []struct {
+	puzzle   []string
+	target   string
+	expected bool
+}{
+	{[]string{"FACI", "OBQP", "ANOB", "MASS"}, "FOAM", true},
+	{[]string{"FACI", "OBQP", "ANOB", "MASS"}, "MASS", true},
+	{[]string{"FACI", "OBQP", "ANOB", "MASS"}, "FBOS", false},
+	{[]string{"FACI", "OBQP", "ANOB", "MASS"}, "F", true},
+	{[]string{"FACI", "OBQP", "ANOB", "MASS"}, "MASSS", false},
+}
+
+func TestFindWordLD(t *testing.T) {
+	t.Parallel()
+	for tcid, tc := range testcases {
+		puzzle := make([][]rune, len(tc.puzzle))
+		for i := range puzzle {
+			puzzle[i] = []rune(tc.puzzle[i])
+		}
+		if result := FindWordLD(puzzle, []rune(tc.target)); result != tc.expected {
+			t.Errorf("TC%d Expected %v got %v", tcid, tc.expected, result)
+		}
+	}
+}
+
+func BenchmarkFindWordLD(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			puzzle := make([][]rune, len(tc.puzzle))
+			for x := range puzzle {
+				puzzle[x] = []rune(tc.puzzle[x])
+			}
+			FindWordLD(puzzle, []rune(tc.target))
+		}
+	}
+}