Sliding Window O(N) TC
Approach\n Describe your approach to solving the problem. \napply sliding window approach to solve the problem, maintain a prevcount for test cases to avoid sub
# Approach\n<!-- Describe your approach to solving the problem. -->\napply sliding window approach to solve the problem, maintain a prevcount for test cases to avoid subarrays with all elements below the range\n\n# Code\n```\nclass Solution {\n    public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n        int p1=0;\n        int p2=0;\n        int count=0;\n        int prevcount=0;\n        while(p2!=nums.length){\n            if(nums[p2]>=left && nums[p2]<=right){\n                count+=p2-p1+1;\n                p2++;\n                prevcount=0;\n            }\n            else if(nums[p2]<left){\n                count+=p2-p1-prevcount;\n                p2++;\n                prevcount++;\n            }\n            else{\n                p2++;\n                p1=p2;\n                prevcount=0;\n            }\n        }\n        return count;\n    }\n}\n```
['Java']