Ctrl K

As Many Times as Its Value

Easy
You are given an integer array numbers. Call a number **honest** if it appears in the array exactly as many times as its own value: 2 twice, 5 five times, and so on. Return the largest honest number. If there is none, return -1.
Example 1
numbers=[3, 1, 3, 4, 3] → 3

3 occurs 3 times and 1 occurs once. Both qualify, and the larger is 3.

Example 2
numbers=[2, 5, 5] → -1

2 occurs once and 5 occurs twice, so no number qualifies.

Example 3
numbers=[1] → 1
Constraints
  • 1 ≤ len(numbers) ≤ 10⁵
  • 1 ≤ numbers[i] ≤ 500
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Candidate With Most Votes EasyValues One Apart EasyEven Piles of Cards EasyMatching Domino Tiles EasyWords From Letter Tiles Easy
loading Python…
Input
numbers=[3, 1, 3, 4, 3]
Expected
3

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