Faster || Easy To Understand || C++ Code
Using Two Pointer\n\n Time Complexity : O(N)\n\n Space Complexity : O(1)\n\n\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& nums, int le
* ***Using Two Pointer***\n\n* ***Time Complexity : O(N)***\n\n* ***Space Complexity : O(1)***\n\n```\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n        \n        int n = nums.size();\n        \n        int start = 0;\n        \n        int end = 0;\n        \n        int prev_count = 0;\n        \n        int ans = 0;\n        \n        while(end < n)\n        {\n            if(nums[end] >= left && nums[end] <= right)\n            {\n                prev_count = end - start + 1;\n                \n                ans += prev_count;\n            }\n            \n            else if(nums[end] < left)\n            {\n                ans += prev_count;\n            }\n            \n            else if(nums[end] > right)\n            {\n                start = end + 1;\n                \n                prev_count = 0;\n            }\n            \n            end++;\n        }\n        \n        return ans;\n    }\n};\n```
['C']