a few solutions
There are 3 buckets which numbers in can be placed into:\n\n1) less than L\n2) less than or equal to R\n3) greater than R\n\nBucket 1 is a subset of Bucket 2.  
There are 3 buckets which numbers in can be placed into:\n\n1) less than `L`\n2) less than or equal to `R`\n3) greater than `R`\n\nBucket 1 is a subset of Bucket 2.  Return the ongoing count of bucket 2 numbers minus the ongoing count of bucket 1 numbers.  Completely ignore bucket 3.  The ongoing count of bucket 1 and 2 is reset back to 0 when a number no longer meets the ongoing count criteria ( "less than L" for bucket 1 and "less than or equal to R" for bucket 2 ).\n\n---\n\n**Solutions from June 17<sup>th</sup> 2021\'s daily challenge:**\n\nConsider the question: "what is the limiting factor for creating a contiguous sub-array?"  The limiting factor can be thought of as the "bare minimum necessity", ie. for each contiguous sub-array the limiting factor is: "the sub-array must include an arbitrary value `x` such that `x` is clamped by `L..R` inclusive."  Let `c` be the count of such sub-arrays.  So let\'s find and return `c`...\n\nLet `a` and `b` be ongoing the count of bucket 1 and 2 correspondingly for values `x` seen during a linear scan of the input array `A`.  Then return the ongoing count `c` of sub-arrays as the accumulated absolute difference between `a` and `b` for each `x` under consideration, ie. since bucket 1 is a subset of bucket 2, we subtract `a` from `b` to accumulate the ongoing count `c` of subarrays with limiting factor `x` as a maximal value between `L..R` inclusive.  Note: `a` is non-inclusive of `L` so when we subtract `a` from `b`, `b` is inclusive of `L`, and thus `b` satisfies count of the property `x` clamped by `L..R` inclusive, ie. `a` is the ongoing count for the  contiguous sub-array under considersation\'s `0, 1, 2, ..., L - 3, L - 2, L - 1` inclusive values and `b` is the ongoing count for the contiguous sub-array under consideration\'s `0, 1, 2, ..., L - 3, L - 2, L - 1, L, L + 1, L + 2, ... , R - 2, R - 1, R` inclusive values, this is why we erase the count of the first `0..L-1` inclusive to only include the count of `L..R` inclusive to be accumulated in `c`.\n\n**Procedural Solutions:**\n\n*Kotlin*\n```\nclass Solution {\n    fun numSubarrayBoundedMax(A: IntArray, L: Int, R: Int): Int {\n        var (a, b, c) = listOf(0, 0, 0)\n        for (x in A) {\n            a = if (x <  L) 1 + a else 0\n            b = if (x <= R) 1 + b else 0\n            c += b - a\n        }\n        return c\n    }\n}\n```\n\n*Javascript*\n```\nlet numSubarrayBoundedMax = (A, L, R) => {\n    let [a, b, c] = [0, 0, 0];\n    for (let x of A) {\n        a = x <  L ? 1 + a : 0;\n        b = x <= R ? 1 + b : 0;\n        c += b - a;\n    }\n    return c;\n};\n```\n\n*Python3*\n```\nclass Solution:\n    def numSubarrayBoundedMax(self, A: List[int], L: int, R: int) -> int:\n        a, b, c = 0, 0, 0\n        for x in A:\n            a = 1 + a if x <  L else 0\n            b = 1 + b if x <= R else 0\n            c += b - a\n        return c\n```\n\n*C++*\n```\nclass Solution {\npublic:\n    using VI = vector<int>;\n    int numSubarrayBoundedMax(VI& A, int L, int R) {\n        auto [a, b, c] = make_tuple(0, 0, 0);\n        for (auto x: A) {\n            a = x <  L ? 1 + a : 0;\n            b = x <= R ? 1 + b : 0;\n            c += b - a;\n        }\n        return c;\n    }\n};\n```\n\n---\n\n**Legacy Solutions (March 4, 2018 5:02 PM):**\n\n**Verbose Solution #1:**\n```\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n        int cnt=0,lessThanLeft=0,lessThanOrEqToRight=0;\n        for (auto n: A){\n \n            if (n<L)\n                ++lessThanLeft;\n            else\n                lessThanLeft=0;\n            \n            if (n<=R)\n                ++lessThanOrEqToRight;\n            else\n                lessThanOrEqToRight=0;\n            \n            cnt+=lessThanOrEqToRight-lessThanLeft;\n        }\n        return cnt;\n    }\n};\n```\n\n**Concise Solution #2:**\n* Let ```i``` represent the ongoing count of bucket 1 numbers ( less than L ).\n* Let ```j``` represent the ongoing count of bucker 2 numbers ( less than or equal to R )\n```\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n        int cnt=0,i=0,j=0;\n        for (auto n: A){\n            i=(n<L) ? i+1 : 0;\n            j=(n<=R) ? j+1 : 0;\n            cnt+=j-i;\n        }\n        return cnt;\n    }\n};\n```\n\n**More Concise Solution #3:**\n* Let ```i``` represent the ongoing count of bucket 1 numbers ( less than L ).\n* Let ```j``` represent the ongoing count of bucket 2 numbers ( less than or equal to R )\n```\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n        int cnt=0,i=0,j=0;\n        for (auto n: A) cnt+=( ++j*=(n<=R) ) - ( ++i*=(n<L) );\n        return cnt;\n    }\n};\n```
[]