Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 solve in c++, no chatgpt please

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions