H-Index - Problem

Given an array of integers citations where citations[i] is the number of citations a researcher received for their i-th paper, 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.

Input & Output

Example 1 — Basic Case
$ Input: citations = [3,0,6,1,5]
Output: 3
💡 Note: The researcher has 3 papers with at least 3 citations each: papers with 6, 5, and 3 citations. The 4th paper has only 1 citation and 5th has 0, so h-index is 3.
Example 2 — All High Citations
$ Input: citations = [1,3,1]
Output: 1
💡 Note: Only 1 paper has at least 1 citation, and only 1 paper has at least 3 citations. The h-index is 1 since we have at least 1 paper with ≥1 citations.
Example 3 — All Zero Citations
$ Input: citations = [0,0]
Output: 0
💡 Note: No papers have any citations, so the h-index is 0.

Constraints

  • 1 ≤ citations.length ≤ 5000
  • 0 ≤ citations[i] ≤ 1000

Visualization

Tap to expand
H-Index Algorithm Visualization INPUT citations array: 3 i=0 0 i=1 6 i=2 1 i=3 5 i=4 Citation counts (visual): 3 0 6 1 5 Find max h where at least h papers have h+ citations n = 5 papers ALGORITHM STEPS 1 Sort Descending [6, 5, 3, 1, 0] 2 Compare index+1 with citation value 3 Find h-index Where citations[i] >= i+1 i val i+1 val>=i+1 0 6 1 OK 1 5 2 OK 2 3 3 OK h=3 3 1 4 NO 4 0 5 NO 4 Return max h where condition holds FINAL RESULT h-index = 3 Meaning: At least 3 papers have 3 or more citations Papers with 3+ citations: 6 5 3 3 papers >= 3 citations Papers with less than 3: 1 0 2 papers less than 3 citations Key Insight: By sorting citations in descending order, we can find h-index by comparing each citation value with its 1-based position. The h-index is the largest position where citations[i] >= position. Time Complexity: O(n log n) for sorting | Space Complexity: O(1) or O(n) depending on sort TutorialsPoint - H-Index | Optimal Solution (Sort and Compare)
Asked in
Google 25 Facebook 20 Amazon 15
28.0K Views
Medium Frequency
~15 min Avg. Time
892 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