1815. Maximum Number of Groups Getting Fresh Donuts Hard

@problem@discussion
#Array#Dynamic Programming#Bit Manipulation#Memoization#Bitmask



1/**
2 * [1815] Maximum Number of Groups Getting Fresh Donuts
3 *
4 * There is a donuts shop that bakes donuts in batches of batchSize. They have a rule where they must serve all of the donuts of a batch before serving any donuts of the next batch. You are given an integer batchSize and an integer array groups, where groups[i] denotes that there is a group of groups[i] customers that will visit the shop. Each customer will get exactly one donut.
5 * When a group visits the shop, all customers of the group must be served before serving any of the following groups. A group will be happy if they all get fresh donuts. That is, the first customer of the group does not receive a donut that was left over from the previous group.
6 * You can freely rearrange the ordering of the groups. Return the maximum possible number of happy groups after rearranging the groups.
7 *  
8 * Example 1:
9 * 
10 * Input: batchSize = 3, groups = [1,2,3,4,5,6]
11 * Output: 4
12 * Explanation: You can arrange the groups as [6,2,4,5,1,3]. Then the 1^st, 2^nd, 4^th, and 6^th groups will be happy.
13 * 
14 * Example 2:
15 * 
16 * Input: batchSize = 4, groups = [1,3,2,5,2,2,1,6]
17 * Output: 4
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	1 <= batchSize <= 9
23 * 	1 <= groups.length <= 30
24 * 	1 <= groups[i] <= 10^9
25 * 
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/maximum-number-of-groups-getting-fresh-donuts/
30// discuss: https://leetcode.com/problems/maximum-number-of-groups-getting-fresh-donuts/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35    pub fn max_happy_groups(batch_size: i32, groups: Vec<i32>) -> i32 {
36        0
37    }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn test_1815() {
48    }
49}
50


Back
© 2025 bowen.ge All Rights Reserved.