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
4mo

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!
Select
Add answer anonymously...

Oyo Rooms Software Developer interview questions & answers

A Software Developer was asked Q. Given the head of a singly linked list and two integers m and n, reverse the nod...read more
A Software Developer was asked Q. Merge sort algorithm and divide array in the chunks
A Software Developer was asked Q. Position of Right Most Set Bit Determine the position of the rightmost set bit i...read more

Popular interview questions of Software Developer

A Software Developer was asked Q1. Given the head of a singly linked list and two integers m and n, reverse the nod...read more
A Software Developer was asked Q2. Merge sort algorithm and divide array in the chunks
A Software Developer was asked Q3. Position of Right Most Set Bit Determine the position of the rightmost set bit i...read more
Oyo Rooms Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits