275. H-Index II

Practice H-Index II for free on NudgeCode: Medium, Binary Search pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

citations[i] is how many times a researcher's i-th paper has been cited, and the array is sorted in ascending order. The researcher's h-index is the largest h such that at least h of the papers have been cited at least h times each.

Return the h-index. Aim for O(log n) time, using the fact that the array is sorted.

Example

citations = [0,1,3,5,6]  ->  3
citations = [1,2,100]    ->  2

In the first case three papers (3, 5 and 6 citations) each have at least 3 citations, but there aren't four papers with at least 4.

Constraints