Problem. A graph started as a tree with n nodes (labelled 1 to n), then one extra edge was added. Given the n edges, return an edge that can be removed so the remaining graph is a tree. If several qualify, return the one that appears last in the input.
edges = [[1, 2], [1, 3], [2, 3]] → [2, 3]
edges = [[1, 2], [2, 3], [3, 4], [1, 4], [1, 5]] → [1, 4]
Add the edges one at a time: the first edge whose two endpoints are already connected closes a cycle, and it's the answer (it's the last edge of that cycle in input order). The whole problem is answering "are u and v already connected?" quickly while edges keep arriving. That's what union-find (disjoint set union) is for.
ML context. Union-find is the engine of record deduplication and entity resolution (lesson 11.15): every "these two records are the same" link merges two clusters. A link between records that are already in the same cluster is redundant, and a "these two are different" constraint between records that end up connected is a contradiction worth flagging (Change D). Kruskal's minimum spanning tree, used in single-linkage clustering, runs the same check on edges sorted by weight.