h-index.sh — zsh
sortingarrayscounting

Given an array citations where citations[i] is the number of citations a researcher's i-th paper received, return the researcher's h-index.

The h-index is defined as the maximum value h such that the researcher has published at least h papers that have each been cited at least h times.

Input / output

  • Input: citations: int[]
  • Output: int — the h-index

Constraints

  • 1 <= citations.length <= 5000
  • 0 <= citations[i] <= 1000

Follow-up

Can you compute the h-index in O(n) time without fully sorting, by bucketing every citation count above n into a single n bucket?

Examples
Example 1
Input: citations = [3,0,6,1,5]
Output: 3
Example 2
Input: citations = [1,3,1]
Output: 1
Example 3
Input: citations = [6,5,3,1,0]
Output: 3