Sliding Window Solution | Python | 0(N) 0(1) clean code | 98 % memory efficent | 95 % faster
count of subarrays having maximum element between left and right will be difference of count of subarrays having maximum element as right and count of subarrays
count of subarrays having maximum element between left and right will be difference of count of subarrays having maximum element as right and count of subarrays having maximum elements less than left. Rest solution is trivial.\n\n\n```\nclass Solution:\n    def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int:\n        \n        def count_subarrays_with_max_atmost_x(x):\n        \n            front = count = 0\n\n            for rear in range(len(nums)):\n\n                if nums[rear] > x:\n\n                    front = rear + 1\n                    continue\n\n                count += rear - front +1\n            \n            return count\n         \n        return count_subarrays_with_max_atmost_x(right) - count_subarrays_with_max_atmost_x(left-1)\n\t\t```
['Sliding Window', 'Python3']