Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 228
Good morning! Here's your coding interview problem for today.

This problem was asked by Twitter.

Given a list of numbers, create an algorithm that arranges them in order to form the largest possible integer. For example, given `[10, 7, 76, 415]`, you should return `77641510`.

Pull request description:
Day228
Resolves #470.

Patch:
diff --git a/README.md b/README.md
index 8cb2218..c1adf43 100644
--- a/README.md
+++ b/README.md
@@ -237,3 +237,4 @@ problems from
 * [Day 224](https://github.com/vaskoz/dailycodingproblem-go/issues/462)
 * [Day 225](https://github.com/vaskoz/dailycodingproblem-go/issues/465)
 * [Day 226](https://github.com/vaskoz/dailycodingproblem-go/issues/467)
+* [Day 228](https://github.com/vaskoz/dailycodingproblem-go/issues/470)
diff --git a/day228/problem.go b/day228/problem.go
new file mode 100644
index 0000000..f5954a8
--- /dev/null
+++ b/day228/problem.go
@@ -0,0 +1,23 @@
+package day228
+
+import (
+	"sort"
+	"strconv"
+	"strings"
+)
+
+// LargestPossibleInteger returns the largest possible integer
+// constructed by these given numbers.
+func LargestPossibleInteger(nums []int) int {
+	strs := make([]string, len(nums))
+	for i, num := range nums {
+		strs[i] = strconv.Itoa(num)
+	}
+	sort.Slice(strs, func(i, j int) bool {
+		first, _ := strconv.Atoi(strs[i] + strs[j])
+		second, _ := strconv.Atoi(strs[j] + strs[i])
+		return first > second
+	})
+	result, _ := strconv.Atoi(strings.Join(strs, ""))
+	return result
+}


Test patch:
diff --git a/day228/problem_test.go b/day228/problem_test.go
new file mode 100644
index 0000000..9f0bc6f
--- /dev/null
+++ b/day228/problem_test.go
@@ -0,0 +1,31 @@
+package day228
+
+import "testing"
+
+var testcases = []struct {
+	nums     []int
+	expected int
+}{
+	{[]int{10, 7, 76, 415}, 77641510},
+	{[]int{7, 76, 789}, 789776},
+	{[]int{789, 7, 76}, 789776},
+	{[]int{789, 76, 7}, 789776},
+	{[]int{791, 7}, 7917},
+}
+
+func TestLargestPossibleInteger(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := LargestPossibleInteger(tc.nums); result != tc.expected {
+			t.Errorf("Expected %d, got %d", tc.expected, result)
+		}
+	}
+}
+
+func BenchmarkLargestPossibleInteger(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			LargestPossibleInteger(tc.nums)
+		}
+	}
+}