2790. Maximum Number of Groups With Increasing Length Hard
1/**
2 * [2790] Maximum Number of Groups With Increasing Length
3 *
4 * You are given a 0-indexed array usageLimits of length n.
5 * Your task is to create groups using numbers from 0 to n - 1, ensuring that each number, i, is used no more than usageLimits[i] times in total across all groups. You must also satisfy the following conditions:
6 *
7 * Each group must consist of distinct numbers, meaning that no duplicate numbers are allowed within a single group.
8 * Each group (except the first one) must have a length strictly greater than the previous group.
9 *
10 * Return an integer denoting the maximum number of groups you can create while satisfying these conditions.
11 *
12 * <strong class="example">Example 1:
13 *
14 * Input: usageLimits = [1,2,5]
15 * Output: 3
16 * Explanation: In this example, we can use 0 at most once, 1 at most twice, and 2 at most five times.
17 * One way of creating the maximum number of groups while satisfying the conditions is:
18 * Group 1 contains the number [2].
19 * Group 2 contains the numbers [1,2].
20 * Group 3 contains the numbers [0,1,2].
21 * It can be shown that the maximum number of groups is 3.
22 * So, the output is 3.
23 * <strong class="example">Example 2:
24 *
25 * Input: usageLimits = [2,1,2]
26 * Output: 2
27 * Explanation: In this example, we can use 0 at most twice, 1 at most once, and 2 at most twice.
28 * One way of creating the maximum number of groups while satisfying the conditions is:
29 * Group 1 contains the number [0].
30 * Group 2 contains the numbers [1,2].
31 * It can be shown that the maximum number of groups is 2.
32 * So, the output is 2.
33 *
34 * <strong class="example">Example 3:
35 *
36 * Input: usageLimits = [1,1]
37 * Output: 1
38 * Explanation: In this example, we can use both 0 and 1 at most once.
39 * One way of creating the maximum number of groups while satisfying the conditions is:
40 * Group 1 contains the number [0].
41 * It can be shown that the maximum number of groups is 1.
42 * So, the output is 1.
43 *
44 *
45 * Constraints:
46 *
47 * 1 <= usageLimits.length <= 10^5
48 * 1 <= usageLimits[i] <= 10^9
49 *
50 */
51pub struct Solution {}
52
53// problem: https://leetcode.com/problems/maximum-number-of-groups-with-increasing-length/
54// discuss: https://leetcode.com/problems/maximum-number-of-groups-with-increasing-length/discuss/?currentPage=1&orderBy=most_votes&query=
55
56// submission codes start here
57
58impl Solution {
59 pub fn max_increasing_groups(usage_limits: Vec<i32>) -> i32 {
60 0
61 }
62}
63
64// submission codes end
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69
70 #[test]
71 fn test_2790() {
72 }
73}
74
Back
© 2025 bowen.ge All Rights Reserved.