less than 1 minute read

You are given a list of non-negative integers nums. If there are exactly k numbers in nums that are greater than or equal to k, return k. Otherwise, return -1.

Constraints

  • 1 ≤ n ≤ 100,000 where n is the length of nums

https://binarysearch.com/problems/K-Numbers-Greater-Than-or-Equal-to-K

Examples

Example 1

Input

  • nums = [5, 3, 0, 9]

Output

  • answer = 3

Explanation

There are exactly 3 numbers that’s greater than or equal to 3: [5, 3, 9].

Solution

Leave a comment