Class Solution
java.lang.Object
g2701_2800.s2790_maximum_number_of_groups_with_increasing_length.Solution
2790 - Maximum Number of Groups With Increasing Length.<p>Hard</p>
<p>You are given a <strong>0-indexed</strong> array <code>usageLimits</code> of length <code>n</code>.</p>
<p>Your task is to create <strong>groups</strong> using numbers from <code>0</code> to <code>n - 1</code>, ensuring that each number, <code>i</code>, is used no more than <code>usageLimits[i]</code> times in total <strong>across all groups</strong>. You must also satisfy the following conditions:</p>
<ul>
<li>Each group must consist of <strong>distinct</strong> numbers, meaning that no duplicate numbers are allowed within a single group.</li>
<li>Each group (except the first one) must have a length <strong>strictly greater</strong> than the previous group.</li>
</ul>
<p>Return <em>an integer denoting the <strong>maximum</strong> number of groups you can create while satisfying these conditions.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> <code>usageLimits</code> = [1,2,5]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong></p>
<p>In this example, we can use 0 at most once, 1 at most twice, and 2 at most five times.</p>
<p>One way of creating the maximum number of groups while satisfying the conditions is:</p>
<p>Group 1 contains the number [2].</p>
<p>Group 2 contains the numbers [1,2].</p>
<p>Group 3 contains the numbers [0,1,2].</p>
<p>It can be shown that the maximum number of groups is 3.</p>
<p>So, the output is 3.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> <code>usageLimits</code> = [2,1,2]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong></p>
<p>In this example, we can use 0 at most twice, 1 at most once, and 2 at most twice.</p>
<p>One way of creating the maximum number of groups while satisfying the conditions is:</p>
<p>Group 1 contains the number [0].</p>
<p>Group 2 contains the numbers [1,2].</p>
<p>It can be shown that the maximum number of groups is 2.</p>
<p>So, the output is 2.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> <code>usageLimits</code> = [1,1]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong></p>
<p>In this example, we can use both 0 and 1 at most once.</p>
<p>One way of creating the maximum number of groups while satisfying the conditions is:</p>
<p>Group 1 contains the number [0].</p>
<p>It can be shown that the maximum number of groups is 1.</p>
<p>So, the output is 1.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= usageLimits.length <= 10<sup>5</sup></code></li>
<li><code>1 <= usageLimits[i] <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxIncreasingGroups
-