commit 264bd7f5022c3452ae13dbb2c0de44ce960affd9
parent 8d772ecef89d3e60977ecd3346e3e8527a481955
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Tue, 20 Feb 2024 11:54:37 +0000
1 Random Problem
Diffstat:
2 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/Problems/2091.cpp b/Problems/2091.cpp
@@ -0,0 +1,23 @@
+class Solution {
+ public:
+ int minimumDeletions(const vector<int> &nums) const {
+ const int n = size(nums);
+ int mini = nums[0], imini = 0;
+ int maxi = nums[0], imaxi = 0;
+
+ for (int i = 1; i < n; i++) {
+ if (mini > nums[i]) {
+ mini = nums[i];
+ imini = i;
+ }
+
+ if (maxi < nums[i]) {
+ maxi = nums[i];
+ imaxi = i;
+ }
+ }
+
+ return min(
+ {imini + n - imaxi + 1, imaxi + n - imini + 1, max(imini, imaxi) + 1, n - min(imini, imaxi)});
+ }
+};
diff --git a/README.md b/README.md
@@ -967,6 +967,7 @@ for solving problems.
| 2079 | Medium | [Watering Plants](Problems/2079.cpp) |
| 2085 | Easy | [Count Common Words With One Occurrence](Problems/2085.cpp) |
| 2090 | Medium | [K Radius Subarray Averages](Problems/2090.cpp) |
+| 2091 | Medium | [Removing Minimum and Maximum From Array](Problems/2091.cpp) |
| 2095 | Medium | [Delete the Middle Node of a Linked List](Problems/2095.cpp) |
| 2101 | Medium | [Detonate the Maximum Bombs](Problems/2101.cpp) |
| 2104 | Medium | [Sum of Subarray Ranges](Problems/2104.cpp) |