878207. Find H-Index for sorted citations

Medium

Here is the Markdown blog post for the problem:

Find H-Index for sorted citations

Summary

The H-Index is a metric used to measure the productivity and citation impact of the publication of a scholar. Given a list of integers representing the number of citations for each of a researcher's papers, find the maximum value of h such that the first h papers are cited at least h times.

This problem involves working with arrays, which require attention to detail and efficient algorithms.

Detailed Explanation

The given array represents the number of citations for each paper. The goal is to find the H-Index, which is the largest possible integer h such that the sum of the first h elements is greater than or equal to h.

Here's a step-by-step approach:

  1. Initialize variables: Set h = 0, i = 0 (index), and sum = 0.
  2. Iterate through the array:
    • For each element, increment i by 1.
    • Add the current element to sum.
    • If sum >= i, update h to i and reset sum to 0.
  3. Return h as the H-Index.

The time complexity for this approach is O(n), where n is the size of the array, because we're iterating through the array once. The space complexity is O(1) since we're not using any additional space that scales with the input size.

Optimized Solutions

Java

View on GeeksforGeeks
public int findHIndex(int[] citations) {
    int h = 0;
    int i = 0;
    int sum = 0;

    for (int citation : citations) {
        i++;
        sum += citation;
        if (sum >= i) {
            h = i;
            sum = 0;
        }
    }

    return h;
}

DevExCode

Master coding interviews with Leetcode, system design, TechBit, QuickLearn, DevTips, Tech Battles, and career services.

© 2026 DevExCode. All rights reserved.