Welcome to the daily solving of our PROBLEM OF THE DAY with Karan Mashru. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Maths but also build up problem-solving skills.
In this problem, we are given, an array of N elements and L and R, and print the number of sub-arrays such that the value of the maximum array element in that subarray is at least L and at most R.
Example :
Input :
Arr = {2, 0, 11, 3, 0}
L = 1 and R = 10
Output :
4
Explanation:
The sub-arrays {2}, {2, 0}, {3} and {3, 0} have maximum in range 1-10.
Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/number-of-subarrays-with-maximum-values-in-given-range5949/1
Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp-compiler/0b07c910-2a04-4d89-af1d-de5b860e3546