King and its Empire !! T.C : O(N)  & S.C : O(!)
Intuition\n Describe your first thoughts on how to solve this problem. \nKing and his Empire\na[i] > R -> villan\na[i] < L -> am janta\na[e]>=L and a[e]<=R -> K
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nKing and his Empire\na[i] > R -> villan\na[i] < L -> am janta\na[e]>=L and a[e]<=R -> King     \n                 \n*Alone King and King + am janta can built the empire\nif Villan comes , he destory the empire .*\n\n# Approach\n1. declare start ,end , ans and empire.\n2. traverse the end 0->N\n3. if ***King*** encounter set the empire \n4. if **villan** encounter reset the empire .\n5. ans + = empire.\n6. return ans;\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& a, int left, int right) {\n        int n = a.size();\n        int s = 0, e =0, ans = 0;\n        int  empire = 0;\n        for( ; e<n;e++){\n            if(a[e]>=left and a[e]<=right){\n                // king built the empire with or without am janta\n                empire = e - s + 1;\n            }\n            else if(a[e]>right){\n                // villan aa gya empire tut jyga;\n                empire = 0;\n                s = e+1;\n            }\n            \n            ans += empire;\n        }\n        \n        return ans;\n    }\n};\n```
['Array', 'Two Pointers', 'Sliding Window', 'C++']