Skip to content
Decoder

H-Index

Medium

Problem

A researcher has published n papers, and citations[i] says how many times paper i has been cited. Their h-index is the largest number h such that **at least h papers have h or more citations each**. Return it.

Example 1

Input
citations = [4, 0, 7, 2, 5]
Output
3
Why
4, 7 and 5 each have at least 3

Example 2

Input
citations = [2, 9, 2]
Output
2

Example 3

Input
citations = [0, 0]
Output
0

Constraints

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

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.