795-Number-Of-Subarrays-With-Bounded-Maximum

Sat 17 May 2025

https://leetcode.com/problems/number-of-subarrays-with-bounded-maximum

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numSubarrayBoundedMax(self, A: List[int], L: int, R: int) -> int:
    ans = 0
    l = -1
    r = -1

    for i, a in enumerate(A):
      if a > R:
        l = i
      if a >= L:
        r = i
      ans += r - l

    return ans
new Solution().numSubarrayBoundedMax()

Score: 5

Category: leetcode