Leetcode Problem 2576. Find the Maximum Number of Marked Indices

2576. Find the Maximum Number of Marked Indices

Leetcode Solutions

Two Pointers (Greedy) Approach

  1. Sort the array nums in non-decreasing order.
  2. Initialize two pointers: i starting at index 0 and j starting at index len(nums) // 2.
  3. Initialize a variable count to keep track of the number of marked indices.
  4. While both i and j are within the bounds of the array: a. If 2 * nums[i] <= nums[j], mark both indices by incrementing count by 2, and move both pointers to the next index. b. If the condition is not met, only move the second pointer j to the next index.
  5. Return the count as the maximum number of marked indices.
UML Thumbnail

Binary Search Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...