Skip to content

H-Index II

MediumBinary Search
Decode it first. Clues, constraints, pattern and plan before any code.

A researcher's papers have citation counts citations, sorted in ascending order. Their h-index is the largest h such that at least h papers have at least h citations each. Return it, in logarithmic time.

citations = [0, 1, 3, 5, 6]   →  3   (three papers have at least 3 citations)
citations = [1, 2, 100]       →  2
citations = [0]               →  0

Constraints

  • 1 <= citations.length <= 10^5
  • 0 <= citations[i] <= 1000
  • citations is sorted in ascending order.