
Special Array With X Elements Greater Than or Equal X (easy)
Problem Statement
You are given an array nums containing positive integers. A nums array is special if there exists a number x such that there are exactly x elements of the array greater than or equal to x.
Return the value of x if the array is special. Otherwise, return -1.
Note: The array may or may not contain the x.
Examples
Example 1:
- Input:
[3, 5, 3, 4] - Expected Output:
-1 - Justification: There's no value X from 1 to 4 such that there are exactly X elements greater than or equal to X.
Example 2:
- Input:
[0, 5, 2, 4, 3] - Expected Output:
3 - Justification: There are 3 elements (5, 4, 3), which are greater than or equal to 3 in the
numsarray.
Example 3:
- Input:
[5, 6, 7, 8, 9] - Expected Output:
5 - Justification: Each number in the array is greater than or equal to 5, and since there are 5 elements in total, 5 is the special value.
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory