Number of Subarrays with Bounded Maximum  DYNAMIC PROGRAMMING Solution
INTUITION :-\nThere are three cases :-\n1.  nums[i]  >  right\n2.  nums[i]  <  left \n3.  nums[i]  >=  left && nums[i]  >=  right\n\ndp[i] represents number of 
INTUITION :-\nThere are three cases :-\n1.  nums[i]  >  right\n2.  nums[i]  <  left \n3.  nums[i]  >=  left && nums[i]  >=  right\n\ndp[i] represents number of subarrays \n1. satisfying condition (3) above , and\n2.  ending at nums[i] \n(nums[i] may or may not be maximum)\n\nCode :-\n```\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& nums, int l, int r) {\n        int n=nums.size();\n        int dp[n];\n        int ct=0,ind=-1;\n        (nums[0]>=l && nums[0]<=r)?dp[0]=1:dp[0]=0;\n        if(nums[0]>r)ind=0;\n        for(int i=1;i<n;i++){\n            if(nums[i]>r){\n                ind=i;\n                dp[i]=0;\n            }\n            else if(nums[i]<l)\n                dp[i]=dp[i-1];\n            else if(nums[i]>=l && nums[i]<=r)\n                dp[i]=i-ind;\n                \n            ct=ct+dp[i];                              //ct is count of all subarrays \n           // cout<<dp[i];\n        }\n        return ct+dp[0];      \n    }\n};\n```\nHope it helps.\n
['Dynamic Programming', 'C']