Skip to content
BytePatterns

H Index From Citations

MediumSorting#sorting#counting~20m

Problem

A researcher's h-index is the largest number h such that at least h of their papers have h or more citations each. Given the citation count of every paper, return the h-index.

Examples

Input:  citations = [3, 0, 6, 1, 5]
Output: 3
Why:    three papers have at least 3 citations; four papers with 4 or more do not exist
Input:  citations = [1, 1]
Output: 1
Why:    one paper has at least 1 citation, but two papers with 2 or more do not
Input:  citations = [0]
Output: 0
Why:    edge case, an uncited paper gives an h-index of zero

Hints

0 / 3

Stuck on the idea rather than the code? Sorting Basics covers it.