Funcia
Lv.1countingsorting

H-Index

Memory limit
256 MB
Correctness time limit
10000 ms
Solvers
0
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

citationsresult
[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

  • 1≤1 \le citations.length ≤200,000\le 200{,}000
  • 0≤0 \le citations[i] ≤109\le 10^9

Expected complexity

Time
O(N log N)
Space
O(N)

Examples

citationsExpected
[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 O(N)O(N). Recounting the whole array for every candidate h is O(N2)O(N^2) and exceeds the time limit.

Time limits per language

LanguageEfficiency time limit
C (GCC, gnu17)200 msestimated
C++ (GCC, gnu++23)200 msderived
Python 3.131000 msderived
Java 251052 msderived
Kotlin 2.4 (JVM)1400 msestimated
C# 14 (.NET 10)1400 msestimated

Test groups

GroupWeightTestsVisibility
sample03inputs and outputs
correctness4011verdict only
performance603verdict only
Loading editor…
Log in to run or submit code.

No result yet. Run or submit your code.