2358. Maximum Number of Groups Entering a Competition Medium
1/**
2 * [2358] Maximum Number of Groups Entering a Competition
3 *
4 * You are given a positive integer array grades which represents the grades of students in a university. You would like to enter all these students into a competition in ordered non-empty groups, such that the ordering meets the following conditions:
5 *
6 * The sum of the grades of students in the i^th group is less than the sum of the grades of students in the (i + 1)^th group, for all groups (except the last).
7 * The total number of students in the i^th group is less than the total number of students in the (i + 1)^th group, for all groups (except the last).
8 *
9 * Return the maximum number of groups that can be formed.
10 *
11 * Example 1:
12 *
13 * Input: grades = [10,6,12,7,3,5]
14 * Output: 3
15 * Explanation: The following is a possible way to form 3 groups of students:
16 * - 1^st group has the students with grades = [12]. Sum of grades: 12. Student count: 1
17 * - 2^nd group has the students with grades = [6,7]. Sum of grades: 6 + 7 = 13. Student count: 2
18 * - 3^rd group has the students with grades = [10,3,5]. Sum of grades: 10 + 3 + 5 = 18. Student count: 3
19 * It can be shown that it is not possible to form more than 3 groups.
20 *
21 * Example 2:
22 *
23 * Input: grades = [8,8]
24 * Output: 1
25 * Explanation: We can only form 1 group, since forming 2 groups would lead to an equal number of students in both groups.
26 *
27 *
28 * Constraints:
29 *
30 * 1 <= grades.length <= 10^5
31 * 1 <= grades[i] <= 10^5
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/maximum-number-of-groups-entering-a-competition/
37// discuss: https://leetcode.com/problems/maximum-number-of-groups-entering-a-competition/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn maximum_groups(grades: Vec<i32>) -> i32 {
43 0
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_2358() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.