Sliding window Approach, Very easy to understand, faster than 97%
Using the sliding window technique we first find the number of subarrays which have maximum value smaller than L and then we find the number of subarrays whose 
Using the sliding window technique we first find the number of subarrays which have maximum value smaller than L and then we find the number of subarrays whose maximum value is smaller than R+1. We subtract these two numbers to find the number of subarrays which have max value in [L,R]\n```\nint numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n\tint n = A.size();\n\tlong long i = 0, j = 0;\n\tlong long smaller_than_L = 0, smaller_than_R_plus_one = 0;\n\twhile(j < n){\n\t\tif(A[j] >= L){\n\t\t\ti = j+1;\n\t\t}\n\t\telse{\n\t\t\tsmaller_than_L += j-i+1;\n\t\t}\n\t\tj++;\n\t}\n\ti = 0, j = 0;\n\twhile(j < n){\n\t\tif(A[j] >= R+1){\n\t\t\ti = j+1;\n\t\t}\n\t\telse{\n\t\t\tsmaller_than_R_plus_one += j-i+1;\n\t\t}\n\t\tj++;\n\t}\n\t//cout << smaller_than_L << "," << smaller_than_R_plus_one;\n\treturn (int)(smaller_than_R_plus_one - smaller_than_L);\n}
[]