Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Integers to Choose From a Range II

Try to solve the Maximum Number of Integers to Choose From a Range II problem.

Statement

You are given an integer array banned and two integers n and maxSum.

You want to choose the maximum number of integers such that:

  • Every chosen integer is in the range [1,n][1, n].

  • Each integer is chosen at most once.

  • None of the chosen integers appear in banned.

  • The total sum of the chosen integers does not exceed maxSum.

Return the maximum number of integers you can choose following these rules.

Constraints:

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

  • 1≤1 \leq banned[i] ≤\leq n ≤109\leq 10^9

  • 1≤1 \leq maxSum ≤1015\leq 10^{15}

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Integers to Choose From a Range II

Try to solve the Maximum Number of Integers to Choose From a Range II problem.

Statement

You are given an integer array banned and two integers n and maxSum.

You want to choose the maximum number of integers such that:

  • Every chosen integer is in the range [1,n][1, n].

  • Each integer is chosen at most once.

  • None of the chosen integers appear in banned.

  • The total sum of the chosen integers does not exceed maxSum.

Return the maximum number of integers you can choose following these rules.

Constraints:

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

  • 1≤1 \leq banned[i] ≤\leq n ≤109\leq 10^9

  • 1≤1 \leq maxSum ≤1015\leq 10^{15}