Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 165
Good morning! Here's your coding interview problem for today.

This problem was asked by Google.

Given an array of integers, return a new array where each element in the new array is the number of smaller elements to the right of that element in the original input array.

For example, given the array `[3, 4, 9, 6, 1]`, return `[1, 1, 2, 1, 0]`, since:

* There is 1 smaller element to the right of 3
* There is 1 smaller element to the right of 4
* There are 2 smaller elements to the right of 9
* There is 1 smaller element to the right of 6
* There are no smaller elements to the right of 1

Pull request description:
Day165
Resolves #343.

Patch:
diff --git a/README.md b/README.md
index 6e93cfe..71d9ed0 100644
--- a/README.md
+++ b/README.md
@@ -175,3 +175,4 @@ problems from
 * [Day 162](https://github.com/vaskoz/dailycodingproblem-go/issues/335)
 * [Day 163](https://github.com/vaskoz/dailycodingproblem-go/issues/336)
 * [Day 164](https://github.com/vaskoz/dailycodingproblem-go/issues/340)
+* [Day 165](https://github.com/vaskoz/dailycodingproblem-go/issues/343)
diff --git a/day165/problem.go b/day165/problem.go
new file mode 100644
index 0000000..9e68185
--- /dev/null
+++ b/day165/problem.go
@@ -0,0 +1,18 @@
+package day165
+
+// SmallerRightCount returns the number of smaller elements
+// to the right of the position.
+// Runs in O(N^2) time.
+func SmallerRightCount(nums []int) []int {
+	result := make([]int, len(nums))
+	for i, v := range nums {
+		count := 0
+		for j := i + 1; j < len(nums); j++ {
+			if v > nums[j] {
+				count++
+			}
+		}
+		result[i] = count
+	}
+	return result
+}


Test patch:
diff --git a/day165/problem_test.go b/day165/problem_test.go
new file mode 100644
index 0000000..5e5752a
--- /dev/null
+++ b/day165/problem_test.go
@@ -0,0 +1,29 @@
+package day165
+
+import (
+	"reflect"
+	"testing"
+)
+
+var testcases = []struct {
+	nums, expected []int
+}{
+	{[]int{3, 4, 9, 6, 1}, []int{1, 1, 2, 1, 0}},
+}
+
+func TestSmallerRightCount(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := SmallerRightCount(tc.nums); !reflect.DeepEqual(result, tc.expected) {
+			t.Errorf("Expected %v got %v", tc.expected, result)
+		}
+	}
+}
+
+func BenchmarkSmallerRightCount(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			SmallerRightCount(tc.nums)
+		}
+	}
+}