2860. Happy Students Medium

@problem@discussion
#Array#Sorting#Enumeration



1/**
2 * [2860] Happy Students
3 *
4 * You are given a 0-indexed integer array nums of length n where n is the total number of students in the class. The class teacher tries to select a group of students so that all the students remain happy.
5 * The i^th student will become happy if one of these two conditions is met:
6 * 
7 * 	The student is selected and the total number of selected students is strictly greater than nums[i].
8 * 	The student is not selected and the total number of selected students is strictly less than nums[i].
9 * 
10 * Return the number of ways to select a group of students so that everyone remains happy.
11 *  
12 * <strong class="example">Example 1:
13 * 
14 * Input: nums = [1,1]
15 * Output: 2
16 * Explanation: 
17 * The two possible ways are:
18 * The class teacher selects no student.
19 * The class teacher selects both students to form the group. 
20 * If the class teacher selects just one student to form a group then the both students will not be happy. Therefore, there are only two possible ways.
21 * 
22 * <strong class="example">Example 2:
23 * 
24 * Input: nums = [6,0,3,3,6,7,2,7]
25 * Output: 3
26 * Explanation: 
27 * The three possible ways are:
28 * The class teacher selects the student with index = 1 to form the group.
29 * The class teacher selects the students with index = 1, 2, 3, 6 to form the group.
30 * The class teacher selects all the students to form the group.
31 * 
32 *  
33 * Constraints:
34 * 
35 * 	1 <= nums.length <= 10^5
36 * 	0 <= nums[i] < nums.length
37 * 
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/happy-students/
42// discuss: https://leetcode.com/problems/happy-students/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47    pub fn count_ways(nums: Vec<i32>) -> i32 {
48        0
49    }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[test]
59    fn test_2860() {
60    }
61}
62


Back
© 2025 bowen.ge All Rights Reserved.