You are given an array nums containing non-negative integers.
We say the array is special if there exists a number x such that exactly x elements in the array have values greater than or equal to x.
Note that x is not required to appear inside the array itself.
Your task is to determine this value x.
If such an x exists, return it.
If no number satisfies the condition, return -1.
It is guaranteed that if a valid x exists, it will be unique.
Input: nums = [1, 2, 3, 4]
Output: 3
Explanation:
There are exactly 2 elements (3,4) that are ≥ 2.
Input: nums = [5, 0, 0, 5, 6]
Output: -1
Explanation:
Three values (5,5,6) are ≥ 3.
Input: nums = [0,1,1]
Output: -1
Explanation:
No value x satisfies “exactly x elements ≥ x”.
Accepted:
Submission: