




Sponsored
Sponsored
This approach uses sorting to calculate the h-index. The idea is to sort the array of citations in descending order. Then, find the maximum number h such that there are h papers with at least h citations. This can be efficiently determined by iterating over the sorted array.
Time Complexity: O(n log n) due to sorting, Space Complexity: O(1) since the sorting is in place.
1using System;
2
3public class Solution {
4    public int HIndex(int[] citations) {
5        Array.Sort(citations);
6        Array.Reverse(citations);
7        int n = citations.Length;
8        for (int i = 0; i < n; i++) {
9            if (citations[i] < i + 1) {
10                return i;
11            }
12        }
13        return n;
14    }
15    
16    public static void Main(string[] args) {
17        int[] citations = {3, 0, 6, 1, 5};
18        Solution sol = new Solution();
19        Console.WriteLine("H-Index: " + sol.HIndex(citations));
20    }
21}This C# solution sorts the array in descending order and determines the h-index in a manner similar to the other solutions provided.
Given the constraints where citation counts do not exceed 1000 and the number of papers is at most 5000, a counting sort or bucket sort can be used. This approach involves creating a frequency array to count citations. Then traverse the frequency array to compute the h-index efficiently.
Time Complexity: O(n + m) where n is citationsSize and m is the maximum citation value, Space Complexity: O(m).
1#
This C implementation uses a frequency array to count papers for citation values. It accumulates from the back (high values) to find the point where the count matches or exceeds the index.