Data Structures & AlgorithmsVery hardAmazon · Microsoft OA
Problem: Insert keys into a hash table of size 7 with open addressing and LINEAR probing, h(k) = k mod 7.
Problem: Insert keys into a hash table of size 7 with open addressing and LINEAR probing, h(k) = k mod 7.
T = [None] * 7
for k in [50, 700, 76, 85, 92, 73, 101]:
i = k % 7
while T[i] is not None: i = (i + 1) % 7
T[i] = k
print(T)What is printed?- A. [700, 50, 85, 92, 73, 101, 76]
- B. [700, 50, 85, 73, 101, 92, 76]
- C. [73, 50, 85, 92, 101, 700, 76]
- D. [700, 50, 92, 85, 73, 101, 76]
Correct answer: A. [700, 50, 85, 92, 73, 101, 76]
Home slots: 50→1, 700→0, 76→6, 85→1 (taken → 2), 92→1 (→ 2 → 3), 73→3 (→ 4), 101→3 (→ 4 → 5). Primary clustering makes later keys probe longer and longer runs.
More Coding Interview Problems questions
- Problem: Double hashing with h1(k) = k mod 11 and h2(k) = 7 − (k mod 7); probe i is (h1 + i·h2) mod 11. Print the slots probed for key 58…
- Problem: Exponential (galloping) search: double the bound until a[hi] ≥ target, then binary search in (hi/2, hi]. Count the comparisons of…
- Problem: Count unique quadruplets (as value multisets) summing to target with sort + two nested loops + two pointers. python def four(a…
- Problem: For each element, the nearest smaller value to its LEFT (−1 if none), with a monotonic stack. python def leftsmaller(a): st, out…
- Problem: Report the first negative number in every window of size k (0 if none), using a queue of negative indices. python from…
- Problem: Reorder a linked list L0 → L1 → … → Ln into L0 → Ln → L1 → Ln−1 → … in place (find middle, reverse second half, merge). python…