Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 176
Good morning! Here's your coding interview problem for today.

This problem was asked by Bloomberg.

Determine whether there exists a one-to-one character mapping from one string s1 to another s2.

For example, given `s1 = abc` and `s2 = bcd`, return `true` since we can map a to b, b to c, and c to d.

Given `s1 = foo` and `s2 = bar`, return `false` since the o cannot map to two characters.

Pull request description:
Day176
Resolves #364.

Patch:
diff --git a/README.md b/README.md
index 782c346..eede14d 100644
--- a/README.md
+++ b/README.md
@@ -185,5 +185,6 @@ problems from
 * [Day 171](https://github.com/vaskoz/dailycodingproblem-go/issues/356)
 * [Day 172](https://github.com/vaskoz/dailycodingproblem-go/issues/358)
 * [Day 173](https://github.com/vaskoz/dailycodingproblem-go/issues/360)
+* [Day 176](https://github.com/vaskoz/dailycodingproblem-go/issues/364)
 * [Day 177](https://github.com/vaskoz/dailycodingproblem-go/issues/365)
 * [Day 178](https://github.com/vaskoz/dailycodingproblem-go/issues/367)
diff --git a/day176/problem.go b/day176/problem.go
new file mode 100644
index 0000000..b505f9b
--- /dev/null
+++ b/day176/problem.go
@@ -0,0 +1,17 @@
+package day176
+
+// DoesMappingExist returns true if a 1-to-1 mapping exists.
+func DoesMappingExist(s1, s2 string) bool {
+	if len(s1) != len(s2) {
+		return false
+	}
+	m := make(map[rune]rune)
+	for i, r := range s1 {
+		if t, exists := m[r]; exists && rune(s2[i]) != t {
+			return false
+		} else if !exists {
+			m[r] = rune(s2[i])
+		}
+	}
+	return true
+}


Test patch:
diff --git a/day176/problem_test.go b/day176/problem_test.go
new file mode 100644
index 0000000..02dd516
--- /dev/null
+++ b/day176/problem_test.go
@@ -0,0 +1,29 @@
+package day176
+
+import "testing"
+
+var testcases = []struct {
+	s1, s2 string
+	exists bool
+}{
+	{"abc", "bcd", true},
+	{"foo", "bar", false},
+	{"a", "bb", false},
+}
+
+func TestDoesMappingExist(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := DoesMappingExist(tc.s1, tc.s2); result != tc.exists {
+			t.Errorf("Expected %v got %v", tc.exists, result)
+		}
+	}
+}
+
+func BenchmarkDoesMappingExist(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			DoesMappingExist(tc.s1, tc.s2)
+		}
+	}
+}