Skip to content
Decoder

H-Index II

Medium

Problem

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.

Example 1

Input
citations = [0, 1, 3, 5, 6]
Output
3
Why
three papers have at least 3 citations

Example 2

Input
citations = [1, 2, 100]
Output
2

Example 3

Input
citations = [0]
Output
0

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.