Java O(n) Faster than 100%, Memory consumption less than 96%
Here,\nsum = the total number of subarray which fit the condition\nc = the streak of numbers which are less than the right value\nav = avoid = the streak of num
Here,\n**sum** = the total number of subarray which fit the condition\n**c** = the streak of numbers which are less than the right value\n**av** = **avoid** = the streak of numbers which are less than the left value\n- - - ------------\nBecause the av can be more than one for eg [2,1,1,3,4] left=2, right=5. here av will be 2 at index 2. so we need to subtract the av from sum\n- - ----\n```\nclass Solution {\n    public int numSubarrayBoundedMax(int[] arr, int l, int r) {\n        long sum=0, c=0, av=0;\n        for(int i=0; i<arr.length; i++){\n            if(arr[i]>=l && arr[i]<=r){\n                c++;\n                sum += c;\n                av=0;\n            }\n            else{\n                if(arr[i]>r){\n                    c=0;\n                    av=0;\n                }\n                else{\n                    av++;\n                    c++;\n                    sum += c-av;\n                }\n            }\n        }\n        return (int)sum;\n    }\n}\n```
['Java']