Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 65
Good morning! Here's your coding interview problem for today.

This problem was asked by Amazon.

Given a N by M matrix of numbers, print out the matrix in a clockwise spiral.

For example, given the following matrix:
```
[[1,  2,  3,  4,  5],
 [6,  7,  8,  9,  10],
 [11, 12, 13, 14, 15],
 [16, 17, 18, 19, 20]]
```
You should print out the following:
```
1
2
3
4
5
10
15
20
19
18
17
16
11
6
7
8
9
14
13
12
```

Pull request description:
Day65
Resolves #139.

Patch:
diff --git a/README.md b/README.md
index fd6c7b0..505e64d 100644
--- a/README.md
+++ b/README.md
@@ -74,3 +74,4 @@ problems from
 * [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)
+* [Day 65](https://github.com/vaskoz/dailycodingproblem-go/issues/139)
diff --git a/day65/problem.go b/day65/problem.go
new file mode 100644
index 0000000..42a54a2
--- /dev/null
+++ b/day65/problem.go
@@ -0,0 +1,49 @@
+package day65
+
+import (
+	"strconv"
+	"strings"
+)
+
+// ClockwiseSpiral returns a string that is a representation of the matrix
+// as a clockwise spiral starting from the top-left [0][0] coordinate.
+func ClockwiseSpiral(matrix [][]int) string {
+	if len(matrix) == 0 {
+		return ""
+	}
+	spiral := make([]string, 0, len(matrix)*len(matrix[0]))
+	var r, c int
+	var left, top, right, bottom int = 0, 0, len(matrix[0]), len(matrix)
+	for left < right && top < bottom {
+		// go right
+		for c < right {
+			spiral = append(spiral, strconv.Itoa(matrix[r][c]))
+			c++
+		}
+		c--
+		r++
+		top++
+		for r < bottom {
+			spiral = append(spiral, strconv.Itoa(matrix[r][c]))
+			r++
+		}
+		r--
+		c--
+		right--
+		for c >= left {
+			spiral = append(spiral, strconv.Itoa(matrix[r][c]))
+			c--
+		}
+		c++
+		r--
+		bottom--
+		for r >= top {
+			spiral = append(spiral, strconv.Itoa(matrix[r][c]))
+			r--
+		}
+		r++
+		c++
+		left++
+	}
+	return strings.Join(spiral, " ")
+}


Test patch:
diff --git a/day65/problem_test.go b/day65/problem_test.go
new file mode 100644
index 0000000..1c4e037
--- /dev/null
+++ b/day65/problem_test.go
@@ -0,0 +1,46 @@
+package day65
+
+import "testing"
+
+var testcases = []struct {
+	matrix   [][]int
+	expected string
+}{
+	{
+		[][]int{{1, 2, 3, 4, 5},
+			{6, 7, 8, 9, 10},
+			{11, 12, 13, 14, 15},
+			{16, 17, 18, 19, 20}},
+		"1 2 3 4 5 10 15 20 19 18 17 16 11 6 7 8 9 14 13 12",
+	},
+	{
+		[][]int{{1, 2},
+			{4, 3}},
+		"1 2 3 4",
+	},
+	{
+		[][]int{{}},
+		"",
+	},
+	{
+		[][]int{},
+		"",
+	},
+}
+
+func TestClockwiseSpiral(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := ClockwiseSpiral(tc.matrix); result != tc.expected {
+			t.Errorf("Expected %v got %v", tc.expected, result)
+		}
+	}
+}
+
+func BenchmarkClockwiseSpiral(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			ClockwiseSpiral(tc.matrix)
+		}
+	}
+}