The H-Index II interview question is a variation of the classic H-Index problem where you are given an array of citations sorted in ascending order. The H-Index is a metric that measures both the productivity and citation impact of a researcher. Specifically, a researcher has an index if of their papers have at least citations each, and the other papers have no more than citations each. In this problem, the primary goal is to find the maximum possible value of efficiently, leveraging the fact that the input array is already sorted.
Companies like Meta and Amazon ask the H-Index II coding problem to test a candidate's ability to optimize a linear search into a logarithmic one. Since the array is sorted, a linear scan () is possible but not optimal. The core challenge is recognizing that the sorted property allows for the use of the binary search interview pattern. It evaluations whether you can correctly identify the search space and the conditions for moving the left and right pointers in a non-standard search scenario.
The primary algorithmic pattern used is Binary Search. The search range is the indices of the array . For any index mid, the number of papers with at least citations[mid] citations is n - mid. We are looking for the smallest index mid such that citations[mid] >= n - mid. This point represents the boundary where the H-Index condition is met.
Imagine a researcher has 5 papers with citations: [0, 1, 3, 5, 6].
low = 0, high = 4.high = 1.mid or mid + 1 instead of n - mid.When you see "Sorted Array" and "Find an optimal value," always think Binary Search. Practice explaining the relationship between the index and the value in this specific context, as the "target" isn't a fixed number but a dynamic condition based on the number of elements remaining.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Minimum Time to Activate String | Medium | Solve | |
| Missing Element in Sorted Array | Medium | Solve | |
| Cutting Ribbons | Medium | Solve | |
| Minimum Time to Complete Trips | Medium | Solve | |
| Minimum Time to Repair Cars | Medium | Solve |