Tap here to switch tabs
Problem
Submissions

Problem: Happy Students

med
30 min
Try to solve the Happy Students problem.

Statement

You are given an integer array nums representing a class of students.

A group of students needs to be selected. A student at index i is happy if and only if one of the following conditions is satisfied:

  • The student is selected and the total number of selected students is strictly greater than nums[i].

  • The student is not selected and the total number of selected students is strictly less than nums[i].

Return the total number of ways to choose a group of students such that every student in the class is happy.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i] << nums.length

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Happy Students

med
30 min
Try to solve the Happy Students problem.

Statement

You are given an integer array nums representing a class of students.

A group of students needs to be selected. A student at index i is happy if and only if one of the following conditions is satisfied:

  • The student is selected and the total number of selected students is strictly greater than nums[i].

  • The student is not selected and the total number of selected students is strictly less than nums[i].

Return the total number of ways to choose a group of students such that every student in the class is happy.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i] << nums.length