Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 83
Good morning! Here's your coding interview problem for today.

This problem was asked by Google.

Invert a binary tree.

For example, given the following tree:
```
    a
   / \
  b   c
 / \  /
d   e f
```
should become:
```
  a
 / \
 c  b
 \  / \
  f e  d
```

Pull request description:
Day83
Resolves #175. 

Patch:
diff --git a/README.md b/README.md
index c4d864c..31366ee 100644
--- a/README.md
+++ b/README.md
@@ -92,3 +92,4 @@ problems from
 * [Day 80](https://github.com/vaskoz/dailycodingproblem-go/issues/168)
 * [Day 81](https://github.com/vaskoz/dailycodingproblem-go/issues/171)
 * [Day 82](https://github.com/vaskoz/dailycodingproblem-go/issues/173)
+* [Day 83](https://github.com/vaskoz/dailycodingproblem-go/issues/175)
diff --git a/day83/problem.go b/day83/problem.go
new file mode 100644
index 0000000..c8040e7
--- /dev/null
+++ b/day83/problem.go
@@ -0,0 +1,17 @@
+package day83
+
+// BinaryTree is a binary tree with string Values.
+type BinaryTree struct {
+	Value       string
+	Left, Right *BinaryTree
+}
+
+// InvertBinaryTree works in-place on the given tree.
+func InvertBinaryTree(tree *BinaryTree) {
+	if tree == nil {
+		return
+	}
+	InvertBinaryTree(tree.Left)
+	InvertBinaryTree(tree.Right)
+	tree.Left, tree.Right = tree.Right, tree.Left
+}


Test patch:
diff --git a/day83/problem_test.go b/day83/problem_test.go
new file mode 100644
index 0000000..006a89d
--- /dev/null
+++ b/day83/problem_test.go
@@ -0,0 +1,42 @@
+package day83
+
+import "testing"
+
+func TestInvertBinaryTree(t *testing.T) {
+	t.Parallel()
+	input := &BinaryTree{"a",
+		&BinaryTree{"b", &BinaryTree{"d", nil, nil}, &BinaryTree{"e", nil, nil}},
+		&BinaryTree{"c", &BinaryTree{"f", nil, nil}, nil}}
+	original := &BinaryTree{"a",
+		&BinaryTree{"b", &BinaryTree{"d", nil, nil}, &BinaryTree{"e", nil, nil}},
+		&BinaryTree{"c", &BinaryTree{"f", nil, nil}, nil}}
+	inverted := &BinaryTree{"a",
+		&BinaryTree{"c", nil, &BinaryTree{"f", nil, nil}},
+		&BinaryTree{"b", &BinaryTree{"e", nil, nil}, &BinaryTree{"d", nil, nil}}}
+	InvertBinaryTree(input)
+	if !equalTrees(input, inverted) {
+		t.Errorf("Expected it to equal the inverted tree")
+	}
+	InvertBinaryTree(input)
+	if !equalTrees(input, original) {
+		t.Errorf("Invert an invert should match the original")
+	}
+}
+
+func BenchmarkInvertBinaryTree(b *testing.B) {
+	input := &BinaryTree{"a",
+		&BinaryTree{"b", &BinaryTree{"d", nil, nil}, &BinaryTree{"e", nil, nil}},
+		&BinaryTree{"c", &BinaryTree{"f", nil, nil}, nil}}
+	for i := 0; i < b.N; i++ {
+		InvertBinaryTree(input)
+	}
+}
+
+func equalTrees(one, two *BinaryTree) bool {
+	if one == nil && two == nil {
+		return true
+	} else if (one == nil && two != nil) || (one != nil && two == nil) || (one.Value != two.Value) {
+		return false
+	}
+	return equalTrees(one.Left, two.Left) || equalTrees(one.Right, two.Right)
+}