C++ solution in O(N)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\nint solve(vector<int> &nums,int x){\n    int i,n=nums.size(),cnt=0,ans=0;\n\n    for(i=0;i<n;i++){\n        if(nums[i]<=x){\n            cnt++;\n            ans+=cnt;\n        }\n        else{\n            cnt=0;\n        }\n    }\n    return ans;\n}\n    int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n        int a=solve(nums,right);\n        int b=solve(nums,left-1);\n\n        return a-b;\n    }\n};\n```
['C++']