The H-Index coding problem asks you to calculate a researcher's h-index based on an array of citation counts for their papers. The h-index is defined as the maximum value h such that the researcher has published at least h papers that have each been cited at least h times.
This problem is widely used by companies like Bloomberg, Amazon, and Meta to evaluate a candidate's understanding of Sorting and Counting Sort optimization. It tests your ability to translate a real-world definition (which can sound confusing) into a concrete mathematical algorithm.
There are two main ways to solve this:
Citations: [3, 0, 6, 1, 5]
Sorting Method:
[6, 5, 3, 1, 0].i=0, val=6. (1 paper).i=1, val=5. (2 papers).i=2, val=3. (3 papers).i=3, val=1. (False).
Result: 3.Bucket Sort Method:
N = 5. Buckets: [0, 0, 0, 0, 0, 0].
0->b[0]=1, 1->b[1]=1, 3->b[3]=1, 5->b[5]=1, 6->b[5]=2.[1, 1, 0, 1, 0, 2].i=5: total = 2. (False).i=4: total = 2. (False).i=3: total = 3. (True!).
Result: 3.h count, or confusing the index with the value.citations[i] >= N - i), leading to off-by-one errors.Always clarify definitions. The h-index sounds tricky: "h papers with at least h citations." Break it down manually with an example before writing any code. Implementing the bucket sort approach is a strong signal of algorithm optimization skills.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Height Checker | Easy | Solve | |
| Maximum Ice Cream Bars | Medium | Solve | |
| Array Partition | Easy | Solve | |
| Minimum Number of Moves to Seat Everyone | Easy | Solve | |
| How Many Numbers Are Smaller Than the Current Number | Easy | Solve |