Boxes of Power Problem Statement
Given a set of boxes represented by an array gainPower
, where each box has a certain power value, along with an initial power value 'power', your task is to maximize the total score by selecting boxes optimally. You can perform one of the following two operations:
Operations:
- If
gainPower[i] ≤ power
, decrease your power bygainPower[i]
, increase your score by 1, and remove the box. - If your score is ≥ 1, increase your power by
gainPower[i]
, decrease your score by 1, and remove the box.
Example:
Input:
T = 1
N = 3, power = 50
gainPower = [20, 30, 40]
Output:
2
Explanation:
You can pick boxes with power values 20 and 30 and perform the operations to get a maximum score of 2.
Constraints:
1 ≤ T ≤ 50
1 ≤ N ≤ 104
1 ≤ gainPower[i], power ≤ 104
Note:
Each box can be used at most once and there's no necessity to remove all the boxes.
AnswerBot
8d
Maximize total score by selecting boxes optimally based on power values and operations.
Iterate through the boxes and perform operations based on power values and current score
Keep track of power, scor...read more
Help your peers!
Add answer anonymously...
Top Media.net Software Services (India) Software Developer interview questions & answers
Popular interview questions of Software Developer
>
Media.net Software Services (India) Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app