java.lang.Object
g2501_2600.s2576_find_the_maximum_number_of_marked_indices.Solution

public class Solution extends Object
2576 - Find the Maximum Number of Marked Indices.<p>Medium</p> <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>.</p> <p>Initially, all of the indices are unmarked. You are allowed to make this operation any number of times:</p> <ul> <li>Pick two <strong>different unmarked</strong> indices <code>i</code> and <code>j</code> such that <code>2 * nums[i] <= nums[j]</code>, then mark <code>i</code> and <code>j</code>.</li> </ul> <p>Return <em>the maximum possible number of marked indices in <code>nums</code> using the above operation any number of times</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [3,5,2,4]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> In the first operation: pick i = 2 and j = 1, the operation is allowed because 2 * nums[2] <= nums[1]. Then mark index 2 and 1. It can be shown that there&rsquo;s no other valid operation so the answer is 2.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [9,2,5,4]</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> In the first operation: pick i = 3 and j = 0, the operation is allowed because 2 * nums[3] <= nums[0].</p> <p>Then mark index 3 and 0.</p> <p>In the second operation: pick i = 1 and j = 2, the operation is allowed because 2 * nums[1] <= nums[2]. Then mark index 1 and 2.</p> <p>Since there is no other operation, the answer is 4.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [7,6,8]</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> There is no valid operation to do, so the answer is 0.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>1 <= nums[i] <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxNumOfMarkedIndices

      public int maxNumOfMarkedIndices(int[] nums)