Easy solution in O(N) in cpp
\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n        int estart=0,send=0,elong=0,ans=0;\n        for(in
```\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n        int estart=0,send=0,elong=0,ans=0;\n        for(int i=0;i<nums.size();i++)\n        {\n            if(nums[i]>=left and nums[i]<=right)\n            {\n                elong=i-estart+1;// 2 1 4 3 3 4\n            }\n            else if(nums[i]>right)\n            {\n                elong=0;\n                estart=i+1;\n            }\n            ans=ans+elong;\n        }\n        return ans;\n        }\n};\n```
[]