Tap here to switch tabs
Problem
Submissions

Problem: Happy Students

Happy Students asks you to count the ways to select a group from an integer array so each selected student has a value below the group size, while each unselected student has a value above it.

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

Happy Students asks you to count the ways to select a group from an integer array so each selected student has a value below the group size, while each unselected student has a value above it.

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