H-Index II - Problem

Given an array of integers citations where citations[i] is the number of citations a researcher received for their i-th paper and citations is sorted in non-descending order, return the researcher's h-index.

According to the definition of h-index on Wikipedia: The h-index is defined as the maximum value of h such that the given researcher has published at least h papers that have each been cited at least h times.

You must write an algorithm that runs in logarithmic time.

Input & Output

Example 1 — Standard Case
$ Input: citations = [0,1,3,5,6]
Output: 3
💡 Note: The researcher has 5 papers with [0,1,3,5,6] citations. 3 papers have at least 3 citations each (papers with 3,5,6 citations), and the other 2 papers have ≤ 3 citations. So h-index is 3.
Example 2 — Higher Citations
$ Input: citations = [1,2,100]
Output: 2
💡 Note: The researcher has 3 papers with [1,2,100] citations. 2 papers have at least 2 citations each (papers with 2,100 citations), and 1 paper has ≤ 2 citations. So h-index is 2.
Example 3 — All Zero Citations
$ Input: citations = [0,0]
Output: 0
💡 Note: Both papers have 0 citations, so no papers have at least 1 citation. H-index is 0.

Constraints

  • 1 ≤ citations.length ≤ 105
  • 0 ≤ citations[i] ≤ 1000
  • citations is sorted in non-descending order

Visualization

Tap to expand
H-Index II: Find maximum h where ≥h papers have ≥h citations01356<3<3≥3≥3≥33 papers (green) have ≥3 citationsCannot have h=4 (only 2 papers with ≥4 citations)Maximum H-Index = 3
Understanding the Visualization
1
Input
Sorted citations array [0,1,3,5,6]
2
Process
Find maximum h where ≥h papers have ≥h citations
3
Output
H-index is 3
Key Takeaway
🎯 Key Insight: Use binary search on the answer since array is sorted - we can check validity in O(1)
Asked in
Google 25 Facebook 20 Amazon 15
28.0K Views
Medium Frequency
~15 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen