There are n chocolates and the weight of the chocolates is given as an array of integers weights[n], where weights[i] denote the weight of the ith chocolate. Every day, one can pick one chocolate, eat half of it, and put the remaining half back. Find the minimum possible total weight of the remaining chocolates after d days. Note that one can eat the same chocolate multiple times. The weight of the part eaten can be calculated as floor(weights[i]/2).
Complete the function findMinWeight in the editor below.
findMinWeight has the following parameters:
int weights[n]: an array of integers representing weights of chocolates, indexed0ton-1int d: an integer representing the number of days
Returns
int: the minimum total weight of chocolates after d days.
𓆝﹏𓊝﹏🫧A heartfelt thank you to A 🐳﹏⋆。°
Examples
01 · Example 1
weights = [30, 20, 25] d = 4 return = 31

Day Weight of the chocolate picked Weight eaten Remaining weight Result
- 1 20 10 10 [30,10,25]
- 2 25 12 13 [30,10,13]
- 3 30 15 15 [15,10,13]
- 4 15 7 8 [8, 10, 13]
02 · Example 2
weights = [2] d = 1 return = 1
On day 1, eat the chocolate with weight 2, and the remaining weight becomes 1. The array becomes [1], with the sum of weights 1.
03 · Example 3
weights = [2, 3] d = 1 return = 4
On day 1, pick either of the chocolates:
- chocolate with weight 2, weights' = [1, 3], with a total weight of 4.
- chocolate with weight 3, weights' = [2, 2], with a total weight of 4.
Constraints
1 ≤ n ≤ 10^51 ≤ weights[i] ≤ 10^4 (where 0 ≤ i < n)1 ≤ d ≤ 2*10^6More Snowflake problems
- Effective Role PrivilegesPHONE SCREEN · Seen May 2026
- Minimum Clicks Between Wiki PagesOA · Seen May 2026
- Minimum Index Distance Between Person and CakeOA · Seen May 2026
- Simple Array Rotation GameSeen Apr 2026
- Max Element Indexes After RotationsOA · Seen Mar 2026
- String Formation (Also for AI/ML Software Engineer Intern :)OA · Seen Mar 2026
- Grid Traversal (Infrastructure Automation Internship)Seen May 2025
- Horizontal Pod Autoscaler (Infrastructure Automation Internship)Seen May 2025
public int findMinWeight(int[] weights, int d) {
// write your code here
}
weights[30, 20, 25]
d4
expected31
sign in to submit