H-Index

MediumArrays & Hashingcounting sort

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

A researcher has published n papers, and citations[i] is the number of times paper i has been cited. Their h-index is the largest integer h such that at least h of the papers have been cited at least h times each. Return the researcher's h-index. Note that h can be 0 and can never exceed n. An O(n) solution is possible.

Examples

Input: citations = [3,0,6,1,5]
Output: 3
Three papers (3, 6, 5 citations) have at least 3 citations each, but there are not four papers with at least 4.
Input: citations = [1,3,1]
Output: 1
At least one paper has 1+ citations, but only one paper has 2 or more.

Constraints

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

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.