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.

AnswerBot
2d

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

Help your peers!
Add answer anonymously...
Oyo Rooms Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter