C++ | Check within valid window
\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n        \n        int n = A.size();\n        int res = 0, left = -1,
```\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n        \n        int n = A.size();\n        int res = 0, left = -1, right = -1;\n        \n        for (int i = 0; i < n; i++) {\n            if (A[i] >= L && A[i] <= R)\n                right = i;\n            else if (A[i] > R) {\n                left = right = i;\n            }\n            res += right-left;\n        }\n    \n        return res;\n    }\n};\n```
[]