What goes in the blank?
# union-find with path compression
def find(x):
if parent[x] != x:
parent[x] = ____(parent[x])
return parent[x]
Answer: find
Recursing to the root and storing it in parent[x] flattens the tree for later lookups.
Play Problem Solving ▸