Pointing one element at another loses whole groups.
Acceptance criteria
- 1.#out should show connected.
Pointing one element at another loses whole groups.
const owner = [0, 1, 2]; function find(x) { while (owner[x] !== x) x = owner[x]; return x; } function union(a, b) { owner[a] = b; } union(0, 1); union(0, 2); document.querySelector('#out').textContent = find(1) === find(2) ? "connected" : "separate";
Output ready when you are
Press Run to render your code, or Submit to validate your solution.