With Explanation Comments: Time: 82 ms (86.62%), Space: 52.2 MB (94.04%)
Like it? ->Upvote please! \u30C4\n\nSolution 1: Two-Pointers Approach\n\nTC: O(n)   //iterate the array\nSC: O(1)\nTime: 174 ms (11.26%), Space: 52.2 MB (68.61%
**Like it? ->Upvote please!** \u30C4\n\n**Solution 1: Two-Pointers Approach**\n\nTC: O(n)   //iterate the array\nSC: O(1)\nTime: 174 ms (11.26%), Space: 52.2 MB (68.61%)\n\n\'\'\'\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n        \n        //initialize a counter & two pointers for the boundaries\n        int counter=0, start=-1, end=-1;\n        \n        for(int i=0;i<nums.size();i++){\n            \n            //move the end pointer to the position of the next invalid number\n            if(nums[i]>right)\n                end=i;\n            //move the start pointer to the position of the first valid number\n            if(nums[i]>=left)\n                start=i;\n            \n            //subtract the two ones to get the distance, number of valid values, between the two poiters & add it to the counter\n            counter+=start-end;\n        }\n        \n        //return the final counter value\n        return counter;\n    }\n};\n\'\'\'\n\n**Solution 2: Three-Pointers Approach**\n\nTC: O(n)   //iterate the array\nSC: O(1)\nTime: 82 ms (86.62%), Space: 52.2 MB (94.04%)\n\n\n\'\'\'\nclass Solution {\npublic:\n    int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n        \n        //initialize a counter & two pointers\n        int counter=0, j=0, k=0;\n        \n        for(int i=0;i<nums.size();i++){\n            \n            //case 1: if the current value is smaller than the bound\n            if(nums[i]<left){\n                //add the third pointer value to the counter\n                counter+=k;\n            }\n            //case 2: if the current value is bigger than the bound\n            else if(nums[i]>right){\n                //return the third pointer to its initial position again\n                k=0;\n                //move the second pointer in the next position of the first one\n                j=i+1;\n            }\n            //case 3: if the current value is in the bound\n            else{\n                //move the third position in the middle position\n                k=(i-j+1);\n                //add the third pointer value to the counter\n                counter+=k;\n            }\n        \n        }\n        \n        //return the final value of the counter\n        return counter;\n    }\n};\n\'\'\'\n\n**Like it? ->Upvote please!** \u30C4\n**If still not understood, feel free to comment. I will help you out**\n**Happy Coding :)**
['Array', 'Two Pointers', 'C', 'C++']