✅✔️Easy implementation using NGL and NGR concepts of stack || C++ Solution✈️✈️✈️✈️✈️
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& arr, int left, int right) {\n        int n = arr.size(), mod = 1e9+7;\n        vector<int>maxLeft(n,-1), maxRight(n,n);\n        stack<pair<int,int>>st1, st2;\n\n        for(int i=0; i<n; i++){\n            while(!st1.empty() && st1.top().first <= arr[i]) st1.pop();\n            if(!st1.empty()) maxLeft[i] = st1.top().second;\n            st1.push({arr[i],i});\n        }\n\n        for(int i=n-1; i>=0; i--){\n            while(!st2.empty() && st2.top().first < arr[i]) st2.pop();\n            if(!st2.empty()) maxRight[i] = st2.top().second;\n            st2.push({arr[i],i});\n        }\n\n        int ans = 0;\n        for(int i=0; i<n; i++){\n            if(arr[i] >= left && arr[i] <= right){\n                ans += ((i - maxLeft[i]) * (maxRight[i]-i) );\n            }\n        }\n\n        return ans;\n    }\n};\n```
['Array', 'Stack', 'Monotonic Stack', 'C++']