Skip to content

Practice Maximum Number of Integers to Choose From a Range I

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2554
LeetCode Problem

Maximum Number of Integers to Choose From a Range I

Problem Statement

Choose distinct integers from 1 through n, excluding every value in banned, with total sum at most maxSum. Return the largest possible number of chosen integers.

Source: Maximum Number of Integers to Choose From a Range I on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
banned = [1,6,5], n = 5, maxSum = 6
Output
2

# Example 2

Input
banned = [1,2,3,4,5,6,7], n = 8, maxSum = 1
Output
0

# Example 3

Input
banned = [11], n = 7, maxSum = 50
Output
7

Constraints

1 <= banned.length <= 10^4
1 <= banned[i], n <= 10^4
1 <= maxSum <= 10^9

Related LeetCode Problems

Practice more problems similar to Maximum Number of Integers to Choose From a Range I.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.