C++ || TC : O(N) SC : O(1) || Optimized ✅
\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n        int ans = 0; // store ans\n        int j=-1; // st
```\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n        int ans = 0; // store ans\n        int j=-1; // starting window\n        int sub = 0; // if current element is less than left bound then count how may element before current element which is less than left and must be continues(it means any element which is greater than left bound reset the count to 0 )\n        for(int i=0;i<nums.size();i++){\n            if(nums[i]>right){\n                j = i;\n                sub = 0;\n            }\n            else if(nums[i]<left){\n                sub++;\n            }\n            else sub = 0;\n            ans = ans + i - j - sub;\n        }\n        return ans;\n    }\n};\n```\nIf You Like Solution Please Upvote :)\nHappy Coding :)
['C']