java easy to understand solution 2 pointers  O(n)
\nclass Solution {\n    public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n       int ans =0;\n       int prevValueCount=0;\n        int n = n
```\nclass Solution {\n    public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n       int ans =0;\n       int prevValueCount=0;\n        int n = nums.length;\n        int i=0;\n        for(int j=0;j<n;j++){\n            if(nums[j]>=left && nums[j]<=right){\n                ans+=j-i+1;\n                prevValueCount=j-i+1;\n            }\n            else if(nums[j]<left){\n                ans+=prevValueCount;\n            }\n            else{ // nums[j]>Right\n                prevValueCount=0;\n                i=j+1;\n            }\n        }\n        \n        return ans;\n    }\n}\n\n```\n\n\n\n\n\n\n\n\n**Please upvote it if you find this solution helpful**
['Java']