C++ two pointer
\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n        int first=0,sec=0,len=nums.size(),ans=0,cons=0;\n 
```\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n        int first=0,sec=0,len=nums.size(),ans=0,cons=0;\n        bool check=true;\n        while(sec<len){\n            if(first==sec){\n                if(nums[sec]>=left && nums[sec]<=right)\n                    ans++;\n                else if(nums[sec]>right){\n                    first=sec+1;\n                }\n                else if(nums[sec]<left){\n                    check=false;\n                }\n                sec++;\n            }\n            else{\n                if(nums[sec]>right){\n                    cons=0;\n                    first=sec+1;\n                    check=true;\n                }\n                else if(nums[sec]<left && check==true){\n                    ans+=sec-first-cons;\n                    cons++;\n                }\n                else if(nums[sec]>=left && nums[sec]<=right){\n                    cons=0;\n                    check=true;\n                    ans+=sec-first+1;\n                }\n                sec++;\n            }\n        }\n        return ans;\n    }\n};\n```
['Two Pointers']