H-Index

Medium#274search the answer

You get the citation counts of a researcher's papers. Their h-index is the largest h such that h of the papers have at least h citations each. Find it. Our example: [6, 0, 3, 11, 1, 5] — the answer is 3: four papers have at least 3 citations, but only three have at least 4.

input
citations: how many times each paper of a researcher was cited.
returns
The h-index: the largest h such that at least h papers were each cited at least h times.
constraints
  • 1 ≤ citations.length ≤ 5000
  • 0 ≤ citations[i] ≤ 1000
our 12 tests keep to them
examples
Open a test in the tests panel: it shows the input and the expected answer.
/**
 * @param {number[]} citations
 * @return {number}
 */
function hIndex(citations) {

}
Ctrl ↵
format
reset

saved in this browser

12 tests · limit 3 s

Stuck?

See the solution run step by step on our example, then why it works and its complexity.

Watch the walkthrough →

Next: more binary search problems

Pattern “Binary search” →

The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.