Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 257
Good morning! Here's your coding interview problem for today.

This problem was asked by WhatsApp.

Given an array of integers out of order, determine the bounds of the smallest window that must be sorted in order for the entire array to be sorted. For example, given `[3, 7, 5, 6, 9]`, you should return `(1, 3)`.

Pull request description:
Day257
Resolves #529.

Patch:
diff --git a/README.md b/README.md
index 57a0148..52f4045 100644
--- a/README.md
+++ b/README.md
@@ -268,4 +268,5 @@ problems from
 * [Day 254](https://github.com/vaskoz/dailycodingproblem-go/issues/523)
 * [Day 255](https://github.com/vaskoz/dailycodingproblem-go/issues/525)
 * [Day 256](https://github.com/vaskoz/dailycodingproblem-go/issues/528)
+* [Day 257](https://github.com/vaskoz/dailycodingproblem-go/issues/529)
 * [Day 258](https://github.com/vaskoz/dailycodingproblem-go/issues/530)
diff --git a/day257/problem.go b/day257/problem.go
new file mode 100644
index 0000000..f73a710
--- /dev/null
+++ b/day257/problem.go
@@ -0,0 +1,26 @@
+package day257
+
+// SmallestWindowThatMustBeSorted returns the smallest window that must be
+// sorted to result in a completely sorted slice.
+func SmallestWindowThatMustBeSorted(nums []int) (start, end int) {
+	maxSoFar := -int(^uint(0)>>1) - 1
+	for i := range nums {
+		if maxSoFar < nums[i] {
+			maxSoFar = nums[i]
+		}
+		if nums[i] < maxSoFar {
+			end = i
+		}
+	}
+	minSoFar := int(^uint(0) >> 1)
+	for i := range nums {
+		j := len(nums) - 1 - i
+		if minSoFar > nums[j] {
+			minSoFar = nums[j]
+		}
+		if nums[j] > minSoFar {
+			start = j
+		}
+	}
+	return
+}


Test patch:
diff --git a/day257/problem_test.go b/day257/problem_test.go
new file mode 100644
index 0000000..a393976
--- /dev/null
+++ b/day257/problem_test.go
@@ -0,0 +1,28 @@
+package day257
+
+import "testing"
+
+// nolint
+var testcases = []struct {
+	nums       []int
+	start, end int
+}{
+	{[]int{3, 7, 5, 6, 9}, 1, 3},
+}
+
+func TestSmallestWindowThatMustBeSorted(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if start, end := SmallestWindowThatMustBeSorted(tc.nums); start != tc.start || end != tc.end {
+			t.Errorf("Expected (%v,%v), got (%v,%v)", tc.start, tc.end, start, end)
+		}
+	}
+}
+
+func BenchmarkSmallestWindowThatMustBeSorted(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			SmallestWindowThatMustBeSorted(tc.nums)
+		}
+	}
+}