---
# System prepended metadata

title: 2576. Find the Maximum Number of Marked Indices
tags: [Leetcode, Two Pointers, Medium, Greedy]

---

# 2576. Find the Maximum Number of Marked Indices
###### tags: `Leetcode` `Medium` `Greedy` `Two Pointers`
Link: https://leetcode.com/problems/find-the-maximum-number-of-marked-indices/description/
## 思路
双指针
首先形成pair 我们肯定优先拿最小的element当```nums[i]```
其次我们不可能组成超过```nums[i]/2```个pairs
所以我们可以拿着前一半element 去match后一半element 看有多少能match上
## Code
```python=
class Solution:
    def maxNumOfMarkedIndices(self, nums: List[int]) -> int:
        nums.sort()
        i, n = 0, len(nums)
        ans = 0
    
        for j in range(n-n//2, n):
            if 2*nums[i]<=nums[j]: 
                ans+=2
                i+=1
        
        return ans
```