Hone logo
Hone
Problems

H-Index II: Finding a Researcher's Impact

The H-index is a metric used to gauge the productivity and citation impact of a researcher. It's defined as the largest number h such that a researcher has at least h papers with at least h citations each. This challenge focuses on calculating the H-index for a researcher whose publications' citation counts are provided in a sorted list.

Problem Description

Given a non-empty array of integers citations representing the citation counts of a researcher's publications, where citations[i] is the number of citations for the i-th publication. The array is sorted in non-decreasing order.

Your task is to compute and return the researcher's h-index.

Key Requirements:

  • The h-index is the largest integer h such that h publications have at least h citations.
  • The input array citations is guaranteed to be sorted in non-decreasing order.

Expected Behavior: The function should return a single integer, which is the calculated h-index.

Edge Cases to Consider:

  • An empty input array (though the problem statement guarantees non-empty).
  • All publications having zero citations.
  • All publications having a very high number of citations.
  • The h-index being equal to the number of publications.
  • The h-index being zero.

Examples

Example 1:

Input: citations = [0, 1, 3, 5, 6]
Output: 3
Explanation:
There are 5 publications.
- The first publication has 0 citations.
- The second publication has 1 citation.
- The third publication has 3 citations.
- The fourth publication has 5 citations.
- The fifth publication has 6 citations.
We can see that 3 publications have at least 3 citations (the publications with 3, 5, and 6 citations).
Also, no `h` greater than 3 satisfies the condition. For example, if we consider h = 4, then we only have 2 publications with at least 4 citations (5 and 6). Thus, the h-index is 3.

Example 2:

Input: citations = [1, 2, 3, 4, 5]
Output: 3
Explanation:
There are 5 publications.
- 3 publications have at least 3 citations (publications with 3, 4, and 5 citations).
- 4 publications have at least 4 citations (publications with 4 and 5 citations) - this is not true.
Thus, the h-index is 3.

Example 3:

Input: citations = [100]
Output: 1
Explanation:
There is 1 publication. It has 100 citations.
1 publication has at least 1 citation.
Thus, the h-index is 1.

Example 4:

Input: citations = [0, 0, 0]
Output: 0
Explanation:
There are 3 publications.
No publication has at least 1 citation.
Thus, the h-index is 0.

Constraints

  • 1 <= citations.length <= 100
  • 0 <= citations[i] <= 1000
  • citations is sorted in non-decreasing order.

Notes

Consider the properties of a sorted array. Can you leverage this to find the h-index more efficiently than a linear scan? Think about how the index i relates to the citation count citations[i] and the potential h-index.

Loading editor...
plaintext