Clean & simple O(n) Java 
\n   public int numSubarrayBoundedMax(int[] A, int L, int R) {\n        int start = -1, last = -1, res = 0;\n        for(int i = 0; i < A.length; i++) {\n      
```\n   public int numSubarrayBoundedMax(int[] A, int L, int R) {\n        int start = -1, last = -1, res = 0;\n        for(int i = 0; i < A.length; i++) {\n            if(A[i] > R) {\n                start = last = i;\n                continue;\n            }\n            \n            if(A[i] >= L)\n                last = i;\n\n            res += last - start;\n        }\n        \n        return res;\n    }\n```
[]