Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 315
Good morning! Here's your coding interview problem for today.

This problem was asked by Google.

In linear algebra, a Toeplitz matrix is one in which the elements on any given diagonal from top left to bottom right are identical.

Here is an example:
```
1 2 3 4 8
5 1 2 3 4
4 5 1 2 3
7 4 5 1 2
```
Write a program to determine whether a given input is a Toeplitz matrix.

Pull request description:
Day315
Resolves #642.

Patch:
diff --git a/README.md b/README.md
index 74a3081..0b12102 100644
--- a/README.md
+++ b/README.md
@@ -321,3 +321,4 @@ problems from
 * [Day 311](https://github.com/vaskoz/dailycodingproblem-go/issues/635)
 * [Day 312](https://github.com/vaskoz/dailycodingproblem-go/issues/637)
 * [Day 314](https://github.com/vaskoz/dailycodingproblem-go/issues/640)
+* [Day 315](https://github.com/vaskoz/dailycodingproblem-go/issues/642)
diff --git a/day315/problem.go b/day315/problem.go
new file mode 100644
index 0000000..4ae30c3
--- /dev/null
+++ b/day315/problem.go
@@ -0,0 +1,32 @@
+package day315
+
+// IsToeplitzMatrix answers if a given matrix is a Toeplitz Matrix.
+// https://en.wikipedia.org/wiki/Toeplitz_matrix
+// Runs in O(N) time and O(1) extra space.
+func IsToeplitzMatrix(mat [][]int) bool {
+	for row := 0; row < len(mat)-1; row++ {
+		r := row
+		c := 0
+		num := mat[r][c]
+		for r < len(mat) && c < len(mat[r]) {
+			if mat[r][c] != num {
+				return false
+			}
+			r++
+			c++
+		}
+	}
+	for col := 1; col < len(mat[0])-1; col++ {
+		r := 0
+		c := col
+		num := mat[r][c]
+		for r < len(mat) && c < len(mat[r]) {
+			if mat[r][c] != num {
+				return false
+			}
+			r++
+			c++
+		}
+	}
+	return true
+}


Test patch:
diff --git a/day315/problem_test.go b/day315/problem_test.go
new file mode 100644
index 0000000..2bf900a
--- /dev/null
+++ b/day315/problem_test.go
@@ -0,0 +1,51 @@
+package day315
+
+import "testing"
+
+// nolint
+var testcases = []struct {
+	mat      [][]int
+	expected bool
+}{
+	{[][]int{
+		{1, 2, 3, 4, 8},
+		{5, 1, 2, 3, 4},
+		{4, 5, 1, 2, 3},
+		{7, 4, 5, 1, 2},
+	},
+		true,
+	},
+	{[][]int{
+		{1, 2, 3, 4, 8},
+		{5, 1, 2, 3, 4},
+		{4, 5, 1, 2, 3},
+		{7, 4, 5, 9, 2},
+	},
+		false,
+	},
+	{[][]int{
+		{1, 2, 3, 4, 8},
+		{5, 1, 2, 3, 4},
+		{4, 5, 1, 2, 3},
+		{7, 4, 5, 1, 9},
+	},
+		false,
+	},
+}
+
+func TestIsToeplitzMatrix(t *testing.T) {
+	t.Parallel()
+	for tcid, tc := range testcases {
+		if result := IsToeplitzMatrix(tc.mat); result != tc.expected {
+			t.Errorf("Expected %v, got %v for TCID %d", tc.expected, result, tcid)
+		}
+	}
+}
+
+func BenchmarkIsToeplitzMatrix(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			IsToeplitzMatrix(tc.mat)
+		}
+	}
+}