java.lang.Object
g2501_2600.s2554_maximum_number_of_integers_to_choose_from_a_range_i.Solution

public class Solution extends Object
2554 - Maximum Number of Integers to Choose From a Range I.<p>Medium</p> <p>You are given an integer array <code>banned</code> and two integers <code>n</code> and <code>maxSum</code>. You are choosing some number of integers following the below rules:</p> <ul> <li>The chosen integers have to be in the range <code>[1, n]</code>.</li> <li>Each integer can be chosen <strong>at most once</strong>.</li> <li>The chosen integers should not be in the array <code>banned</code>.</li> <li>The sum of the chosen integers should not exceed <code>maxSum</code>.</li> </ul> <p>Return <em>the <strong>maximum</strong> number of integers you can choose following the mentioned rules</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> banned = [1,6,5], n = 5, maxSum = 6</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong></p> <p>You can choose the integers 2 and 4.</p> <p>2 and 4 are from the range [1, 5], both did not appear in banned, and their sum is 6, which did not exceed maxSum.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> banned = [1,2,3,4,5,6,7], n = 8, maxSum = 1</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong></p> <p>You cannot choose any integer while following the mentioned conditions.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> banned = [11], n = 7, maxSum = 50</p> <p><strong>Output:</strong> 7</p> <p><strong>Explanation:</strong></p> <p>You can choose the integers 1, 2, 3, 4, 5, 6, and 7. They are from the range [1, 7], all did not appear in banned, and their sum is 28, which did not exceed maxSum.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= banned.length <= 10<sup>4</sup></code></li> <li><code>1 <= banned[i], n <= 10<sup>4</sup></code></li> <li><code>1 <= maxSum <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxCount

      public int maxCount(int[] banned, int n, int maxSum)