Imagine you're organizing pairs of numbers where one number is at least double the other! You have an array of integers, and your goal is to create as many valid pairs as possible.
The Challenge: Given a 0-indexed integer array nums, you need to find the maximum number of indices you can mark by pairing them strategically.
Pairing Rule: You can pick two different unmarked indices i and j where 2 * nums[i] β€ nums[j], then mark both indices. This means nums[j] must be at least twice as large as nums[i].
Goal: Return the maximum possible number of marked indices. Since each successful pairing marks 2 indices, you want to maximize the number of valid pairs you can form.
Example: In array [3, 5, 2, 4], you can pair index 2 (value 2) with index 1 (value 5) since 2 * 2 β€ 5, marking 2 indices total.
Input & Output
Constraints
- 1 β€ nums.length β€ 105
- 1 β€ nums[i] β€ 109
- nums.length is always even (important for optimal pairing)