Data Structures & AlgorithmsModerateTCS NQT Digital · Product Company SDE
Problem: A researcher's h-index is the largest h such that at least h papers have ≥ h citations each.
Problem: A researcher's h-index is the largest h such that at least h papers have ≥ h citations each.
def h_index(c):
c = sorted(c, reverse=True); h = 0
for i, x in enumerate(c):
if x >= i + 1: h = i + 1
else: break
return h
print(h_index([6, 0, 3, 5, 1, 4]), h_index([10, 10, 10]), h_index([0, 0]))What is printed?- A. 3 3 1
- B. 3 3 0
- C. 3 10 0
- D. 4 3 0
Correct answer: B. 3 3 0
Sorted descending: 6, 5, 4, 3, 1, 0; the i-th paper (1-based) still has ≥ i citations for i = 1, 2, 3 (4 ≥ 3) but not i = 4 (3 < 4) → 3. Three papers can give at most h = 3 even with 10 citations each. O(n log n); counting sort gives O(n).
More Coding Interview Problems questions
- Problem: A 3 × 4 matrix is sorted row-wise and each row starts after the previous row ends. Search it as one virtual sorted array of R·C…
- Problem: A truck holds at most 8 boxes. Each box type is (count, units per box). Maximise the total units loaded. python def…
- Problem: Reorder the letters of s so that letters listed in order appear in that order; letters not in order go last, keeping their…
- Problem: A sorted list of distinct positive IDs has gaps. Find the k-th positive integer missing from it in O(log n): before index i, a[i]…
- Problem: Find the minimum of a rotated sorted array that may contain DUPLICATES. python def findmin(a): lo, hi = 0, len(a) - 1 while lo <…
- Problem: Arrange non-negative integers so that their concatenation forms the largest number (returned as a string). Sort with the…