C++ Simple and Easy Explained Solution
Brief Explanation:\nThere are three cases:\n1. The current number is greater than right - there are no new subarrays to add to res. We just update prev_bigger_t
**Brief Explanation:**\nThere are three cases:\n1. The current number is greater than right - there are no new subarrays to add to res. We just update prev_bigger_than_r = current index.\n2. The current number is smaller than left - we can add the new number to all valid previous subarrays which end here so far. But the current number can\'t form it\'s own valid subarray.\n3. The current number is between right and left. In this case we add the new number to all valid previous subarrays which end here so far and the number itself can form a valid subarray too.\n```\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n        int res = 0;\n        int prev_bigger_than_r = -1;\n        int count_prev = 0;\n        \n        for (int i = 0; i < nums.size(); i++) {\n            if (nums[i] > right) {\n                prev_bigger_than_r = i;\n                count_prev = 0;\n            }\n            \n            else if (nums[i] < left) {\n                res += count_prev;\n            }\n            \n            else {\n                count_prev = i - prev_bigger_than_r;\n                res += count_prev;\n                \n            }\n        }\n        return res;\n    }\n};\n```
['C']