Description

Given a sorted array of citations in ascending order, return the h-index in O(log n) time using binary search.

Examples

Input:citations = [0,1,3,5,6]
Output:3
Explanation:

3 papers with ≥3 citations.

Input:citations = [0,0,0,4,4]
Output:2
Explanation:

2 papers have at least 2 citations each. It is not possible to have h-index of 3 because only 2 papers have ≥3 citations, but the requirement is at least 3 papers with ≥3 citations.

Input:citations = [10,10,10,10,10]
Output:5
Explanation:

All 5 papers have at least 5 citations each, so the h-index is 5. This demonstrates the case where all papers exceed the h-index threshold.

Constraints

  • 1 ≤ n ≤ 10⁵

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!