O(n) with easy readable comments | 100% faster | Java
Please upvote if you find this simple to understand\n\npublic int numSubarrayBoundedMax(int[] nums, int left, int right) {\n        \n        // Initialize star
Please upvote if you find this simple to understand\n\npublic int numSubarrayBoundedMax(int[] nums, int left, int right) {\n        \n        // Initialize start and end with -1 \n        int start = -1, end = -1, count = 0;\n        for(int i=0; i<nums.length; i++){\n            \n            // If number less than left then only prefix count will be added again\n            if(nums[i] < left)\n                count += end - start;\n            \n            // If number is greater than right then we reset values and start building  prefix again\n            else if(nums[i] > right){\n                start = i;\n                end = i;\n            }\n            \n            // else if number is valid then we can update end at current position and get add the new prefix\n            else{\n                end = i;\n                count += end - start;\n            }\n        }\n        return count;\n    }
['Java']