Ctrl K

Self-Counting Threshold

Easy
You are given an array of non-negative integers scores. Find an integer x such that exactly x elements of the array are greater than or equal to x. The value x itself does not have to appear in the array. It can be shown that if such an x exists, it is unique. Return it, or -1 if there is none.
Example 1
scores=[9, 1, 4, 3] → 3

Exactly three values are at least 3: 9, 4 and 3.

Example 2
scores=[1, 1] → -1

Both values are at least 1, which is two rather than one; none is at least 2. No x fits.

Example 3
scores=[0, 0, 5] → 1

Only one value, 5, is at least 1.

Constraints
  • 1 ≤ len(scores) ≤ 100
  • 0 ≤ scores[i] ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Lost Ticket EasyValues in Both Lists EasyShared Values With Repeats EasyEven Out the Shelves EasyBest Pair Under the Limit Easy
loading Python…
Input
scores=[9, 1, 4, 3]
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 75 tests on the server, hidden ones included.