Maximum Profit Problem Statement
Mukesh is evaluating the maximum profit from his business over a series of days. Given a list of profits over 'N' days, Mukesh wants to determine the highest profit achievable over any consecutive days within a specified range {‘A’, ‘B’}. The task is to find this maximum profit.
Input:
The first line contains an integer ‘T’ representing the number of test cases.
For each test case:
- The first line consists of three integers ‘N’, ‘A’, ‘B’ where:
-- ‘N’ is the number of days with profit data,
-- ‘A’ is the minimum number of consecutive days to consider,
-- ‘B’ is the maximum number of consecutive days to consider.
- The second line includes ‘N’ integers representing the profits for each day.
Output:
Output the maximum achievable profit from any set of consecutive days within the {‘A’, ‘B’} constraints for each test case on a new line.
Example:
Input:
1
5 1 3
-1 2 3 -4 5
Output:
5
Explanation: The maximum profit over any set of consecutive days with lengths between 1 and 3 is 5, taken from the subarray [5].
Constraints:
- 1 <= T <= 100
- 1 <= N <= 2000
- 1 <= A <= B <= N
- -100000 <= profit[i] <= 100000
Note: You do not need to print anything; the execution should handle the output internally and return the results.
The task is to find the maximum profit achievable over any consecutive days within a specified range {‘A’, ‘B’}.
Iterate through the profit array and calculate the cumulative sum for each possible cons...read more
Top Oyo Rooms Software Developer interview questions & answers
Popular interview questions of Software Developer
Reviews
Interviews
Salaries
Users/Month