commit 74bce8397f734d08eeb7a33b19dfbf902c7e2dec
parent fc58c7b6ef7699ceaed49c0c827e5ec17fc7d08d
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Fri, 15 Nov 2024 23:36:50 +0100
Daily Problem
Diffstat:
2 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/Problems/1574.cpp b/Problems/1574.cpp
@@ -0,0 +1,24 @@
+class Solution {
+ public:
+ int findLengthOfShortestSubarray(const vector<int> &arr) const {
+ const int n = size(arr);
+ int i = 0, j = n - 1;
+
+ while (i + 1 < n && arr[i] <= arr[i + 1])
+ i++;
+ if (i == n - 1) return 0;
+
+ while (j > i && arr[j - 1] <= arr[j])
+ j--;
+
+ int res = min(n - i - 1, j);
+ for (int k = 0; k <= i && j < n;) {
+ if (arr[j] >= arr[k])
+ res = min(res, j - k++ - 1);
+ else
+ j++;
+ }
+
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -971,6 +971,7 @@ reference and a base for solving problems.
| 1568 | Hard | [Minimum Number of Days to Disconnect Island](Problems/1568.cpp) |
| 1569 | Hard | [Number of Ways to Reorder Array to Get Same BST](Problems/1569.cpp) |
| 1572 | Easy | [Matrix Diagonal Sum](Problems/1572.cpp) |
+| 1574 | Medium | [Shortest Subarray to be Removed to Make Array Sorted](Problems/1574.cpp) |
| 1575 | Medium | [Count All Possible Routes](Problems/1575.cpp) |
| 1578 | Medium | [Minimum Time to Make Rope Colorful](Problems/1578.cpp) |
| 1579 | Hard | [Remove Max Number of Edges to Keep Graph Fully Traversable](Problems/1579.cpp) |