Skip to content

Practice Special Array With X Elements Greater Than or Equal X

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#1608
LeetCode Problem

Special Array With X Elements Greater Than or Equal X

Problem Statement

You are given an array nums of non-negative integers. nums is considered special if there exists a number x such that there are exactly x numbers in nums that are greater than or equal to x. Notice that x does not have to be an element in nums. Return x if the array is special, otherwise, return -1. It can be proven that if nums is special, the value for x is unique.

Source: Special Array With X Elements Greater Than or Equal X on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [3,5]
Output
2

# Example 2

Input
nums = [0,0]
Output
-1

# Example 3

Input
nums = [0,4,3,0,4]
Output
3

Constraints

1 <= nums.length <= 100
0 <= nums[i] <= 1000

Related LeetCode Problems

Practice more problems similar to Special Array With X Elements Greater Than or Equal X.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.