LeetCode solutions

1730. Special Array With X Elements Greater Than or Equal X

My accepted Python solution to LeetCode problem 1730, Special Array With X Elements Greater Than or Equal X, running in 7ms.

  • Difficulty: Easy
  • Python
  • Runtime 7ms
  • Memory 17.2MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 7ms, memory 17.2MB, accepted 2025-12-31.

python
class Solution:
    def specialArray(self, nums: List[int]) -> int:
        n = len(nums)
        for x in range(n + 1):
            count = sum(1 for num in nums if num >= x)
            if count == x:
                return x
        return -1

Source