πDay 2. Find H-Index π§
The problem can be found at the following link: Problem Link
π‘ Problem Description:
You are given an array of integers citations[], where citations[i] is the number of citations a researcher received for the i-th paper. Your task is to find the H-Index of the researcher.
H-Index is the largest value H such that the researcher has at least H papers that have been cited at least H times.
π Example Walkthrough:
Input:
citations[] = [3, 0, 5, 3, 0]
Output:
3
Explanation: There are at least 3 papers (with 3, 5, and 3 citations) that have been cited at least 3 times.
Input:
citations[] = [5, 1, 2, 4, 1]
Output:
2
Explanation: There are at least 2 papers (with 5 and 4 citations) that have been cited at least 2 times.
Input:
citations[] = [0, 0]
Output:
0
Explanation: No paper has been cited at least once.
Constraints:
$
1 β€ citations.size() β€ 10^6$$
0 β€ citations[i] β€ 10^6$
π― My Approach:
Bucket Sort Method:
We create an array
buckets[]wherebuckets[i]stores the count of papers with exactlyicitations.If a paper has citations greater than or equal to the number of papers, it is counted in a special
buckets[n].After building the bucket, we compute the cumulative count of papers with at least
icitations to determine the H-Index.
Steps:
Traverse the
citations[]array to populate thebuckets[].Traverse the
buckets[]array from the back to compute the cumulative counts and find the H-Index.This approach ensures a linear time complexity.
π Time and Auxiliary Space Complexity
Expected Time Complexity: O(n), where
nis the size of thecitationsarray. We perform one traversal to populate thebuckets[]and another traversal to compute the H-Index.Expected Auxiliary Space Complexity: O(n), as we use an array of size
n+1for the bucket sort.
π Solution Code
Code (C)
Code (Cpp)
Code (Java)
Code (Python)
π― Contribution and Support:
For discussions, questions, or doubts related to this solution, feel free to connect on LinkedIn: Any Questions. Letβs make this learning journey more collaborative!
β If you find this helpful, please give this repository a star! β
πVisitor Count
Last updated