[JAVA] 100% FAST SOLUTION WITH COMMENTS || TWO POINTERS
class Solution {\n\n    public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n        int ans = 0; \n        int i = 0; \n        int j = 0;\n   
class Solution {\n\n    public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n        int ans = 0; \n        int i = 0; \n        int j = 0;\n        int prev = 0;\n        while(j<nums.length){\n            if(nums[j]>=left && nums[j]<=right){\n                prev = j-i+1;   //if in range adding all subarrays including the curr element\n                ans += prev;\n            }else if(nums[j]<left){\n                ans += prev; // if curr ele less than left then add all the subarrays except the subarray with only one elemnt with curr ele val.\n            }else{\n                i = j+1;\n                prev = 0;   // if greater than range then reset prev subarrays counter and shift starting point to next elemnt.\n            }\n            j++;\n        }\n        return ans;\n    }\n}
['Two Pointers', 'Java']