Data Structures & AlgorithmsVery hardGoldman Sachs OA · LeetCode medium-hard
Problem: Maximum bipartite matching between workers (left) and jobs (right) with Kuhn's augmenting-path algorithm.
Problem: Maximum bipartite matching between workers (left) and jobs (right) with Kuhn's augmenting-path algorithm.
adj = {0: [0, 1], 1: [0], 2: [1, 2], 3: [2], 4: [2, 3]}
match = {}
def try_(u, seen):
for v in adj[u]:
if v in seen: continue
seen.add(v)
if v not in match or try_(match[v], seen):
match[v] = u; return True
return False
print(sum(try_(u, set()) for u in adj))What is printed?- A. 5
- B. 3
- C. 4
- D. 2
Correct answer: C. 4
There are only 4 jobs, so at most 4 matches. Augmenting paths re-route earlier choices: worker 1 needs job 0, pushing worker 0 to job 1, which pushes worker 2 to job 2, and so on. The result 4 equals the brute-force maximum.
More Coding Interview Problems questions
- Problem: Maximum flow from s = 0 to t = 5 with Edmonds–Karp (BFS augmenting paths). python from collections import deque cap = [[0]6 for…
- Problem: Does an undirected connected graph have an Euler path / Euler circuit? (count odd-degree vertices) python from collections import…
- Problem: Count Hamiltonian paths (ordered sequences visiting every vertex once) in a small undirected graph with bitmask DP. python n = 5…
- Problem: Reconstruct an actual longest strictly increasing subsequence with the O(n²) DP and parent pointers (the first maximal end index…
- Problem: Minimum number of single-character insertions plus deletions to turn a into b (no replacements). python def insdel(a, b): m, n =…
- Problem: Fibonacci modulo 10⁹ + 7 by 2 × 2 matrix exponentiation in O(log n). python MOD = 109 + 7 def mul(A, B): return [[(A[0][0]B[0][0]…