Compute the largest h such that at least h papers have at least h citations.
H-Index
gfgYou are given an array of non-negative integers representing citation counts for a researcher’s papers. Find the researcher's H-index.
The H-index is the largest integer such that the researcher has at least papers with at least citations each.
Your task is to return that maximum value.
Input Format
- A single integer array
citationswherecitations[i]is the citation count of the -th paper.
Output Format
- Return a single integer: the H-index.
Constraints
1 <= citations.length <= 50000 <= citations[i] <= 1000- The answer is always a valid integer in the range
[0, citations.length]
Example 1
Input
citations = [3,0,6,1,5]
Output
3
Explanation
There are 3 papers with at least 3 citations each: 3, 5, and 6. There are not 4 papers with at least 4 citations each.
Example 2
Input
citations = [1,3,1]
Output
1
Explanation
At least 1 paper has at least 1 citation, but there are not 2 papers with at least 2 citations.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.