274. H-Index LeetCode Solution
In this guide, you will get 274. H-Index LeetCode Solution with the best time and space complexity. The solution to H-Index problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- H-Index solution in C++
- H-Index solution in Java
- H-Index solution in Python
- Additional Resources

Problem Statement of H-Index
Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith 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.
Example 1:
Input: citations = [3,0,6,1,5]
Output: 3
Explanation: [3,0,6,1,5] means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively.
Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3.
Example 2:
Input: citations = [1,3,1]
Output: 1
Constraints:
n == citations.length
1 <= n <= 5000
0 <= citations[i] <= 1000
Complexity Analysis
- Time Complexity: O(n)
- Space Complexity: O(n)
274. H-Index LeetCode Solution in C++
class Solution {
public:
int hIndex(vector<int>& citations) {
const int n = citations.size();
int accumulate = 0;
vector<int> count(n + 1);
for (const int citation : citations)
++count[min(citation, n)];
// To find the maximum h-index, loop from the back to the front.
// i := the candidate's h-index
for (int i = n; i >= 0; --i) {
accumulate += count[i];
if (accumulate >= i)
return i;
}
throw;
}
};
/* code provided by PROGIEZ */
274. H-Index LeetCode Solution in Java
class Solution {
public int hIndex(int[] citations) {
final int n = citations.length;
int accumulate = 0;
int[] count = new int[n + 1];
for (final int citation : citations)
++count[Math.min(citation, n)];
// To find the maximum h-index, loop from the back to the front.
// i := the candidate's h-index
for (int i = n; i >= 0; --i) {
accumulate += count[i];
if (accumulate >= i)
return i;
}
throw new IllegalArgumentException();
}
}
// code provided by PROGIEZ
274. H-Index LeetCode Solution in Python
class Solution:
def hIndex(self, citations: list[int]) -> int:
n = len(citations)
accumulate = 0
count = [0] * (n + 1)
for citation in citations:
count[min(citation, n)] += 1
# To find the maximum h-index, loop from the back to the front.
# i := the candidate's h-index
for i, c in reversed(list(enumerate(count))):
accumulate += c
if accumulate >= i:
return i
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.