commit 622aee9981e9952b07796f994c7395163e5bffdd
parent 66bd23394c5e1386f75e07a36b03e16c18aa7d0d
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Thu, 21 Mar 2024 20:47:29 +0000
1 Random Problem
Diffstat:
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/Problems/0795.cpp b/Problems/0795.cpp
@@ -0,0 +1,19 @@
+class Solution {
+ public:
+ int numSubarrayBoundedMax(const vector<int> &nums, int left, int right) const {
+ int res = 0, good = -1, last = -1;
+
+ for (int i = 0; i < size(nums); i++) {
+ if (nums[i] < left)
+ res += good - last;
+ else if (nums[i] > right)
+ good = last = i;
+ else {
+ res += i - last;
+ good = i;
+ }
+ }
+
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -479,6 +479,7 @@ for solving problems.
| 0789 | Medium | [Escape The Ghosts](Problems/0789.cpp) |
| 0790 | Medium | [Domino and Tromino Tiling](Problems/0790.cpp) |
| 0791 | Medium | [Custom Sort String](Problems/0791.cpp) |
+| 0795 | Medium | [Number of Subarrays with Bounded Maximum](Problems/0795.cpp) |
| 0797 | Medium | [All Paths From Source to Target](Problems/0797.cpp) |
| 0799 | Medium | [Champagne Tower](Problems/0799.cpp) |
| 0802 | Medium | [Find Eventual Safe States](Problems/0802.cpp) |