Union find: Given n nodes and undirected connections, return the number of connected groups after applying every connection.
Input: A JSON object { "n": number, "connections": [number, number][] }.
Output: A JSON integer group count.
Constraints:
- 0 <= n <= 100000
- Every endpoint is in 0..n-1
- Repeated and self connections do not change the answer
Read one JSON value from stdin and print exactly one JSON-serialized answer to stdout with no extra text.
Difficulty: EASY. Variant: 7. Expect follow-up questions about complexity, edge cases, and alternative approaches.
Practice context
This coding (algo) exercise trains prompt interpretation, explicit assumptions, a concrete response, and a concise explanation of the decisions made. It is marked easy difficulty.
The signed-in workspace provides the tools required by the round, such as recording, code execution, diagrams, structu