Python 3 - counting
Use 2 counters: count1 keeps track of the length of subarrays that do not exceed R. count2 keeps the length of the subarrays that also do not go below L. While 
Use 2 counters: `count1` keeps track of the length of subarrays that do not exceed R. `count2` keeps the length of the subarrays that also do not go below L. While if we have an element falling below L, we update the answer only based on the old value of `count2`, but we still keep `count1` incrementing.\n\n```python\nclass Solution:\n    def numSubarrayBoundedMax(self, A: List[int], L: int, R: int) -> int:\n        ans = count1 = count2 = 0\n        size = len(A)\n        for j in range(size):\n            if A[j] > R:\n                count1 = count2 = 0\n            elif L <= A[j] <= R:\n                count2 = count1 = count1 + 1\n                ans += count1\n            else:\n                count1 += 1\n                ans += count2\n        return ans\n```
[]