Java: Sliding Window , O(n) , passes 100% runtime
\nclass Solution {\n    public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n        int leftPointer = 0, rightPointer = 0;\n        int n = num
```\nclass Solution {\n    public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n        int leftPointer = 0, rightPointer = 0;\n        int n = nums.length;\n        int count = 0;\n        int number = 0;\n        while(leftPointer<n && rightPointer<n) {\n                if(nums[rightPointer]>=left && nums[rightPointer]<=right) {\n\t\t\t\t\t/* variable "number" signifies the last element greater satisfying this condition. \n\t\t\t\t\tWhy we are keeping this count is if a number less than left is there, then this number can be a part of that array.\n\t\t\t\t\tExample: \n\t\t\t\t\t[79,69,33,52,68,5,78] , left = 32, right = 80\n\t\t\t\t\t for number 5 present in 5th index of the array, the possible combinations will include \n\t\t\t\t\t [79,69,33,52,68,5],\n\t\t\t\t\t [69,33,52,68,5],\n\t\t\t\t\t [33,52,68,5],\n\t\t\t\t\t [52,68,5]\n\t\t\t\t\t [68,5]\n\t\t\t\t\t \n\t\t\t\t\t if you see clearly here, the number of combinations that include 5 are the same as the number \n\t\t\t\t\t of combinations that are possible with 68( the last element till 5 which is greater than 32 and less than 80).\n\t\t\t\t\t To keep track of this count we have stored this in variable "number".\n\t\t\t\t\t*/\n\t\t\t\t\n                    count+=(rightPointer-leftPointer+1);\n                    number = (rightPointer-leftPointer+1); \n                } else if(nums[rightPointer]<left) {count+=number;}\n             else {\n                if(nums[rightPointer]>right) {           \n\t\t\t\t\t// reset everything if the array element is greater than right.\n                    rightPointer++;  \n                    leftPointer = rightPointer;\n                    number = 0;\n                    continue;\n                }\n            }\n            rightPointer++;\n        }\n        return count;\n    }\n```\n\nHope this solution helps you. Please comment down if you have any doubts.
['Sliding Window', 'Java']