H-Index
- Memory limit
- 256 MB
- Correctness time limit
- 10000 ms
- Solvers
- 0
citations[i] is the number of times a researcher's i-th paper was cited. The researcher's H-index is the largest
integer h such that at least h papers have at least h citations each. Return it (0 if no h ≥ 1 qualifies).
Examples
| citations | result |
|---|---|
[3, 0, 6, 1, 5] | 3 |
[1, 3, 1] | 1 |
[0, 0] | 0 |
Example 1 — three papers (3, 6, 5) have at least 3 citations, but only two have at least 4.
Efficiency
This problem has performance tests. Judge the required time complexity from the input sizes in the constraints.
Function signature
solution(citations: int[]) → int
Constraints
-
citations.length -
citations[i]
Expected complexity
- Time
- O(N log N)
- Space
- O(N)
Examples
| citations | Expected |
|---|---|
[3,0,6,1,5] | 3 |
[1,3,1] | 1 |
[0,0] | 0 |
Hint
Hint
Sort the citations in descending order: if the k-th paper (1-based) has at least k citations, at least k papers do.
The answer is the last k for which this holds. Alternatively clamp each count to n, bucket them and scan h from n
down, which is . Recounting the whole array for every candidate h is and exceeds the time limit.
Time limits per language
| Language | Efficiency time limit | |
|---|---|---|
| C (GCC, gnu17) | 200 ms | estimated |
| C++ (GCC, gnu++23) | 200 ms | derived |
| Python 3.13 | 1000 ms | derived |
| Java 25 | 1052 ms | derived |
| Kotlin 2.4 (JVM) | 1400 ms | estimated |
| C# 14 (.NET 10) | 1400 ms | estimated |
Test groups
| Group | Weight | Tests | Visibility |
|---|---|---|---|
| sample | 0 | 3 | inputs and outputs |
| correctness | 40 | 11 | verdict only |
| performance | 60 | 3 | verdict only |