Skip to main content
Back to problems
#274
Medium Algorithms

H index

Array Sorting Counting Sort
41.2% acceptance
Jan 12, 2026
1878
898
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.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn h_index(citations: Vec<i32>) -> i32 {
    let mut citations = citations;
    citations.sort_unstable_by(|a, b| b.cmp(a));
    
    let mut h = 0;
    for (i, &citation) in citations.iter().enumerate() {
      if citation >= (i + 1) as i32 {
        h = i + 1;
      } else {
        break;
      }
    }
    
    h as i32
  }
}