Skip to content

Commit aff75eb

Browse files
authored
Create 795-number-of-subarrays-with-bounded-maximum.js
1 parent 9c75025 commit aff75eb

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {number[]} A
3+
* @param {number} L
4+
* @param {number} R
5+
* @return {number}
6+
*/
7+
const numSubarrayBoundedMax = function(A, L, R) {
8+
let res = 0;
9+
let j = 0;
10+
let count = 0;
11+
for(let i = 0; i < A.length; i++) {
12+
if(A[i] >= L && A[i] <= R) {
13+
res += i - j + 1
14+
count = i - j + 1
15+
} else if(A[i] < L) {
16+
res += count
17+
} else {
18+
j = i + 1
19+
count = 0
20+
}
21+
}
22+
return res
23+
};

0 commit comments

Comments
 (0)