[Python] simple O(n) solution, explained
Let us iterate through numbers and keep index of last number which is >= L and index of last number, which is > R. Then, we can quickly calculate number of suba
Let us iterate through numbers and keep index of last number which is `>= L` and index of last number, which is `> R`. Then, we can quickly calculate number of subarrays with bounded maximum which ends on symbol with index `i`: in our window at least one number `>= L`, no numbers `> R`, so we calculate`L_ind - R_ind`. Note, that this number can never be negative, because if `num > R` then `num >= L` since L <= R.\n\n#### Complexity\nTime complexity is `O(n)`, space is `O(1)`.\n\n#### Code\n\n```python\nclass Solution:\n    def numSubarrayBoundedMax(self, A, L, R):\n        L_ind, R_ind, ans = -1, -1, 0\n        for i, num in enumerate(A):\n            if num >= L: L_ind = i\n            if num > R:  R_ind = i\n            ans += L_ind - R_ind\n        return ans\n```\n\nIf you have any question, feel free to ask. If you like the explanations, please **Upvote!**
[]