Java || Beats 100% || Two Pointers O(N) time, O(1) space.
Intuition\nTwo pointers\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nThe main points in this problem are :\n- If we pick a subar
# Intuition\n**Two pointers**\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n**The main points in this problem are :**\n- If we pick a subarray it should contain a element within left and right .\n- The subarray should not contain a element greater than right due to which we can break the array and solve the left and right sub-arrays independently.\n-  The pointer i represents the index of the last split.\n- We should also maintain the index of last occurence of the desired element(>=left && <= right).\n- The count of subarrays for this split ending with this element (j) would be (lastoccurence - i +1).\n- Eg: Imagine left as 2 and right as 3\n\n---\n\n\nFor the elements,\n0 1 2 3 4 5 => index\n1 2 3 1 1 1 => values\nThe subarrays ending with the last index are : \n1 2 3 1 1 1\n2 3 1 1 1\n3 1 1 1\nlastoccurence = 2\ni = 0\nCount of subarrays ending with index 5 would be (2 - 0 + 1) = 3\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity : $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity : $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n        int i = 0, j = 0, res = 0, maxind = -1;\n        while(j < nums.length){\n            if(nums[j] >= left && nums[j] <= right){\n                maxind = j;\n            }\n            if(nums[j] > right){\n                j++;\n                i = j;\n                maxind = -1;\n                continue;\n            }\n            if(maxind != -1){\n                res += maxind - i + 1;\n            }\n            j++;\n        }\n        return res;\n    }\n}\n```
['Two Pointers', 'Greedy', 'Sliding Window', 'Java']