commit 8a0c74ecbb680913f1e071669749337abf824af0
parent 74bce8397f734d08eeb7a33b19dfbf902c7e2dec
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Sat, 16 Nov 2024 20:28:44 +0100
Daily Problem
Diffstat:
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/Problems/0581.cpp b/Problems/0581.cpp
@@ -0,0 +1,18 @@
+class Solution {
+ public:
+ int findUnsortedSubarray(const vector<int> &nums) const {
+ const int n = size(nums);
+ int mini = nums[n - 1], maxi = nums[0];
+ int low = -1, high = -2;
+
+ for (int i = 1; i < n; i++) {
+ mini = min(mini, nums[n - i - 1]);
+ maxi = max(maxi, nums[i]);
+
+ if (nums[i] < maxi) high = i;
+ if (nums[n - i - 1] > mini) low = n - i - 1;
+ }
+
+ return high - low + 1;
+ }
+};
diff --git a/README.md b/README.md
@@ -466,6 +466,7 @@ reference and a base for solving problems.
| 0572 | Easy | [Subtree of Another Tree](Problems/0572.cpp) |
| 0576 | Medium | [Out of Boundary Paths](Problems/0576.cpp) |
| 0577 | Easy | [Employee Bonus](Problems/0577.cpp) |
+| 0581 | Medium | [Shortest Unsorted Continuous Subarray](Problems/0581.cpp) |
| 0583 | Medium | [Delete Operation for Two Strings](Problems/0583.cpp) |
| 0584 | Easy | [Find Customer Referee](Problems/0584.cpp) |
| 0585 | Medium | [Investments in 2016](Problems/0585.cpp) |