C++ O(n) simple solution
\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n        int count = 0, maxCurrent=-1, maxCurrentIndex = -1;\n       
```\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n        int count = 0, maxCurrent=-1, maxCurrentIndex = -1;\n        for (int i = 0, j = 0; i < A.size(); ++i)\n        {\n            if (A[i] <= R)\n            {\n                if (A[i] >= L)\n                    maxCurrentIndex = i;\n                count += maxCurrentIndex - j + 1;\n            }\n            else\n            {\n                j = i + 1;;\n                maxCurrent = -1;\n                maxCurrentIndex = i;\n            }\n        }\n        return count;\n    }\n};\n```
[]