H-Index - Problem

Imagine you're a researcher who has published several papers, and you want to measure your academic impact using the prestigious H-Index metric.

Given an array citations where citations[i] represents the number of citations your i-th paper has received, calculate your H-Index.

The H-Index is defined as: The maximum value h such that you have published at least h papers that have each been cited at least h times.

Example: If you have papers with citations [3, 0, 6, 1, 5], your H-Index is 3 because you have 3 papers with at least 3 citations each (papers with 3, 6, and 5 citations), but you don't have 4 papers with at least 4 citations each.

Input & Output

example_1.py โ€” Standard Case
$ Input: [3,0,6,1,5]
โ€บ Output: 3
๐Ÿ’ก Note: The researcher has 3 papers with at least 3 citations each (papers with 3, 6, and 5 citations), but only 2 papers with at least 4 citations each. So the H-Index is 3.
example_2.py โ€” All High Citations
$ Input: [1,3,1]
โ€บ Output: 1
๐Ÿ’ก Note: The researcher has only 1 paper with at least 3 citations, 2 papers with at least 1 citation. The maximum H-Index possible is 1.
example_3.py โ€” Edge Case Single Paper
$ Input: [100]
โ€บ Output: 1
๐Ÿ’ก Note: With only 1 paper (even with 100 citations), the maximum H-Index is 1, since we can have at most 1 paper with at least 1 citation.

Constraints

  • n == citations.length
  • 1 โ‰ค n โ‰ค 5000
  • 0 โ‰ค citations[i] โ‰ค 1000

Visualization

Tap to expand
H-Index: The Academic Impact Sweet SpotVisual Analogy: Stacking Papers by Citations6Paper 15Paper 23Paper 31Paper 40Paper 5Finding the H-Index3We have 3 papers with โ‰ฅ3 citations eachBut only 2 papers with โ‰ฅ4 citationsTherefore, H-Index = 3Optimal Algorithm Summary1. Create n+1 buckets for citation counts2. Count papers in each range3. Scan right-to-left to find max valid hTime: O(n) | Space: O(n)
Understanding the Visualization
1
Understand the Problem
We need the maximum h where we have โ‰ฅh papers with โ‰ฅh citations each
2
Sort by Citations
Arrange papers in descending order of citations for easier analysis
3
Find the Balance Point
The H-Index is where the number of papers meets the citation requirement
4
Optimal Counting
Use buckets to count efficiently without sorting
Key Takeaway
๐ŸŽฏ Key Insight: The H-Index represents the perfect balance between quantity and quality of research impact - the highest number where you have that many highly-cited papers.
Asked in
Google 42 Microsoft 38 Amazon 31 Apple 24
73.9K Views
Medium Frequency
~18 min Avg. Time
1.8K 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