✅ CPP || Explained with Comments || Easy Understanding || Sliding Window is everywhere
\n// super smart intuition\n        // basic idea is to calculate how many subarrays possible such that\n        // we include an element which satisfies >=left
```\n// super smart intuition\n        // basic idea is to calculate how many subarrays possible such that\n        // we include an element which satisfies >=left and <=right\n        // i.e all subarrays with satisfying that element to be the maximum\n        // suppose we start from 0th index\n        \n\t\t//Case1    // we encounter an element which is less than the lower bound\n                    // i.e the "left" ==> it alone cant be a part of the answer\n                    // but there can be some element which fits in the range\n                    // so we increment j in search of that element\n                    // if we find any such element ==> all subarrays including that element should be calculated\n                    // which will be j-i\n        \n        //Case2     // if we dont encounter any such element j will finally go to n and we wont find any such answer\n                    // what if there is an element greater than right in the array\n                    // smart to exclude that element, right?\n                    // so just jump both i and j to the next value of that element;\n                    // without adding any of it to result\n        \n        //Case3     // suppose we calculate answer for all subarrays between i to j \n                    // after that we move j and encounter an element x which is smaller than x;\n                    // now it can be a part of all the subarrays generated earlier\n                    // so we store it in some temporary variable to use it again\n                    // similarly if we get some greater element the temporary variable\n                    // needs to be reinitialized to 0 since the greater element wont produce any subarrays\n\t\n```\n\t\t\t\t\n```\nint numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n        \n        int n=nums.size();\n        int i=-1,j=0;\n        int ans=0;\n        int prev=0;\n        \n        \n        while(j<n){\n            if(nums[j]>=left and nums[j]<=right){\n                ans+=j-i;\n                prev=j-i;\n                j++;\n            }\n            else if(nums[j]<=left){\n                ans+=prev;\n                j++;\n            }\n            else{\n                prev=0;\n                i=j;\n                j++;\n            }\n        }\n        \n        return ans;\n        \n        \n    }
['Sliding Window', 'C++']