{"id":"55f8d048-6db0-4a30-8b3a-1d6d550c393b","name":"Number Of Subarrays With Bounded Maximum","description":"1. We have an array 'arr' of positive integers, and two positive integers left and right (left is smaller than right).\r\n2. Return the number of (contiguous, non-empty) subarrays such that the value of the maximum array element in that subarray is at least left and at most right.\r\n","inputFormat":"arr = [2, 1, 4, 3]\r\nleft = 2\r\nright = 3","outputFormat":"3\r\nExplanation: There are three subarrays that meet the requirements: [2], [2, 1], [3].","constraints":"1. left, right, and arr[i] will be an integer in the range [0, 10^9].\r\n2. The length of arr will be in the range of [1, 10000].\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\n\n int numSubarrayBoundedMax(vector<int> arr, int left, int right) {\n // write your code here\n \n return ans;\n }\n\n int main() {\n \n int n;\n cin>>n;\n vector<int> arr(n);\n for (int i = 0; i < n; i++) {\n cin>>arr[i];\n }\n\n int left;\n cin>>left;\n int right;\n cin>>right;\n\n int count = numSubarrayBoundedMax(arr, left, right);\n cout<<count;\n }"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int numSubarrayBoundedMax(int[] arr, int left, int right) {\r\n // write your code here\r\n }\r\n\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int left = scn.nextInt();\r\n int right = scn.nextInt();\r\n\r\n int count = numSubarrayBoundedMax(arr, left, right);\r\n System.out.println(count);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"4\r\n2 1 4 3\r\n2\r\n3","sampleOutput":"3","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"3da49540-4335-4978-b68c-6b4896192353","name":"Number Of Subarrays With Bounded Maximum","slug":"number-of-subarrays-with-bounded-maximum","type":1}],"next":{"id":"c1140024-33de-4bdf-881b-a9f79b93b005","name":"Number Of Subarrays With Bounded Maximum","type":3,"slug":"number-of-subarrays-with-bounded-maximum"},"prev":{"id":"f274374f-580e-4d12-bf41-cead88f20c7b","name":"Max Area Of Island MCQ","type":0,"slug":"max-area-of-island-mcq"}}}

Number Of Subarrays With Bounded Maximum

1. We have an array 'arr' of positive integers, and two positive integers left and right (left is smaller than right). 2. Return the number of (contiguous, non-empty) subarrays such that the value of the maximum array element in that subarray is at least left and at most right.

{"id":"55f8d048-6db0-4a30-8b3a-1d6d550c393b","name":"Number Of Subarrays With Bounded Maximum","description":"1. We have an array 'arr' of positive integers, and two positive integers left and right (left is smaller than right).\r\n2. Return the number of (contiguous, non-empty) subarrays such that the value of the maximum array element in that subarray is at least left and at most right.\r\n","inputFormat":"arr = [2, 1, 4, 3]\r\nleft = 2\r\nright = 3","outputFormat":"3\r\nExplanation: There are three subarrays that meet the requirements: [2], [2, 1], [3].","constraints":"1. left, right, and arr[i] will be an integer in the range [0, 10^9].\r\n2. The length of arr will be in the range of [1, 10000].\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\n\n int numSubarrayBoundedMax(vector<int> arr, int left, int right) {\n // write your code here\n \n return ans;\n }\n\n int main() {\n \n int n;\n cin>>n;\n vector<int> arr(n);\n for (int i = 0; i < n; i++) {\n cin>>arr[i];\n }\n\n int left;\n cin>>left;\n int right;\n cin>>right;\n\n int count = numSubarrayBoundedMax(arr, left, right);\n cout<<count;\n }"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int numSubarrayBoundedMax(int[] arr, int left, int right) {\r\n // write your code here\r\n }\r\n\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int left = scn.nextInt();\r\n int right = scn.nextInt();\r\n\r\n int count = numSubarrayBoundedMax(arr, left, right);\r\n System.out.println(count);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"4\r\n2 1 4 3\r\n2\r\n3","sampleOutput":"3","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"3da49540-4335-4978-b68c-6b4896192353","name":"Number Of Subarrays With Bounded Maximum","slug":"number-of-subarrays-with-bounded-maximum","type":1}],"next":{"id":"c1140024-33de-4bdf-881b-a9f79b93b005","name":"Number Of Subarrays With Bounded Maximum","type":3,"slug":"number-of-subarrays-with-bounded-maximum"},"prev":{"id":"f274374f-580e-4d12-bf41-cead88f20c7b","name":"Max Area Of Island MCQ","type":0,"slug":"max-area-of-island-mcq"}}}
plane

Editor


Loading...

Number Of Subarrays With Bounded Maximum

easy

1. We have an array 'arr' of positive integers, and two positive integers left and right (left is smaller than right). 2. Return the number of (contiguous, non-empty) subarrays such that the value of the maximum array element in that subarray is at least left and at most right.

Constraints

1. left, right, and arr[i] will be an integer in the range [0, 10^9]. 2. The length of arr will be in the range of [1, 10000].

Format

Input

arr = [2, 1, 4, 3] left = 2 right = 3

Output

3 Explanation: There are three subarrays that meet the requirements: [2], [2, 1], [3].

Example

Sample Input

4 2 1 4 3 2 3

Sample Output

3

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode