Question: Given an array arr of size N , you have to find the length of the longest subarray such that product of the elements in

Given an array arr of size N, you have to find the length of the longest subarray such that product of the elements in the subarray divided by the factorial of its length is maximized.
Example 1:
Input:
5
34152
Output:
2
Explaination:
We can choose subarray 34 for maximum product of (3*4)/2=6, we can see that there is no other subarray of length greater than 2 having product greater than 6.
Example 2:
Input:
6
174516
Output:
3
Explaination:
The subarray with maximum such value is 745.
Your Task:
You don't need to read input or print anything. Your task is to complete the function longestBeautifulSubarray() which takes the array of integers n and arr as parameters and returns an integer, denoting the answer.
Constraints:
1<= N <=10^5
1<= arr[i]<=10^4 Write the c++ code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!