Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 106
Good morning! Here's your coding interview problem for today.

This problem was asked by Pinterest.

Given an integer list where each number represents the number of hops you can make, determine whether you can reach to the last index starting at index 0.

For example, `[2, 0, 1, 0]` returns `true` while `[1, 1, 0, 1]` returns `false`.

Pull request description:
Day106
Resolves #223.

Patch:
diff --git a/README.md b/README.md
index e1ff522..24deacd 100644
--- a/README.md
+++ b/README.md
@@ -115,3 +115,4 @@ problems from
 * [Day 103](https://github.com/vaskoz/dailycodingproblem-go/issues/217)
 * [Day 104](https://github.com/vaskoz/dailycodingproblem-go/issues/219)
 * [Day 105](https://github.com/vaskoz/dailycodingproblem-go/issues/221)
+* [Day 106](https://github.com/vaskoz/dailycodingproblem-go/issues/223)
diff --git a/day106/problem.go b/day106/problem.go
new file mode 100644
index 0000000..4f35dbe
--- /dev/null
+++ b/day106/problem.go
@@ -0,0 +1,13 @@
+package day106
+
+// CanHopToEnd can you hop from 0 to the end.
+func CanHopToEnd(hops []int) bool {
+	start, end := 0, len(hops)-1
+	for start < end {
+		if hops[start] == 0 {
+			break
+		}
+		start += hops[start]
+	}
+	return start == end
+}


Test patch:
diff --git a/day106/problem_test.go b/day106/problem_test.go
new file mode 100644
index 0000000..cbed1fc
--- /dev/null
+++ b/day106/problem_test.go
@@ -0,0 +1,28 @@
+package day106
+
+import "testing"
+
+var testcases = []struct {
+	hops     []int
+	expected bool
+}{
+	{[]int{2, 0, 1, 0}, true},
+	{[]int{1, 1, 0, 1}, false},
+}
+
+func TestCanHopToEnd(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := CanHopToEnd(tc.hops); result != tc.expected {
+			t.Errorf("For %v expected %v got %v", tc.hops, tc.expected, result)
+		}
+	}
+}
+
+func BenchmarkCanHopToEnd(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			CanHopToEnd(tc.hops)
+		}
+	}
+}