Java O(n) Sliding Window
For each window if the new element is in range (L,R), we add window size m=(j-i+1) to the count. This remains same until we get a new element in range (then we 
For each window if the new element is in range (L,R), we add window size m=(j-i+1) to the count. This remains same until we get a new element in range (then we recompute window size m=j-i+1. If new element is greater than R, we update i to j and we set m=0;\n```\nclass Solution {\n    public int numSubarrayBoundedMax(int[] A, int L, int R) {\n        int i=0,j=0,cnt=0,m=0; //m is the number of subarrays that will be added when this element got added\n        while(j<A.length){\n            if(A[j]>=L && A[j]<=R)\n                m=j-i+1;\n            else if(A[j]>R){ \n                m=0;\n                i=j+1;\n            }\n            cnt+=m;\n            j++;\n        }\n        return cnt;\n    }\n}\n```
[]