H-Index II

MediumBinary Searchbinary search

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's citations array lists how many times each of their papers was cited, **sorted in ascending order**. Their h-index is the largest integer h such that at least h papers each have at least h citations. Return the h-index. Because the input is already sorted, your solution should run in O(log n) time.

Examples

Input: citations = [0,1,3,5,6]
Output: 3
Three papers (3, 5, 6 citations) have at least 3 citations, but there are not four papers with at least 4.
Input: citations = [1,2,100]
Output: 2
Two papers have at least 2 citations; there are not three papers with at least 3.

Constraints

  • 1 <= citations.length <= 10^5
  • 0 <= citations[i] <= 1000
  • `citations` is sorted in non-decreasing order

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.

More binary search problems