THE CHALLENGESPECIAL_ARRAY — How many elements are at least that big?
An array is special if there is an integer x such that exactly x elements are greater than or equal to x. Print x (it is unique if it exists) or -1.
Input:
- line 1: n
- line 2: n integers
Output:
x or -1.
Example:
2
3 5
gives
2
How to break it down:
1. tableau_special(tab): for each candidate x from 1 to n, counts the elements >= x and checks for equality.
2. Print the first x found, otherwise -1.
Challenge: for each candidate x from 1 to n, count the elements >= x - two levels of loops, sorted() is not allowed.
Checks (verified automatically before your code runs):
- At least 1 function definition.
- At least 1 call to tableau_special().
- Loops may be nested at most 2 levels deep.
- Do not use sorted().