Back to problems

Connectivity Queries on Dynamic Components (Union-Find)

Algorithm · Uber · Medium

Problem You are given n nodes labelled 1 through n and a sequence of m operations. Each operation is either: union a b – merge the connected components that contain a and b. query x y – ask whether x and y are currently in the same connected component. Process the operations in the order they appear and return the answer for every query. Function Signature Examples Example 1 Input: Output: [true, false, true, false] Explanation: union 1 2 – node 1 and 2 become connected.…

Checking your access…