Graph traversal: Given n nodes numbered 0 through n-1 and undirected edges, return the number of connected components, including isolated nodes.
Input: A JSON object { "n": number, "edges": [number, number][] }.
Output: A JSON integer component count.
Constraints:
- 0 <= n <= 100000
- Every edge endpoint is in 0..n-1
- Self-edges and repeated edges do not create extra components
Read one JSON value from stdin and print exactly one JSON-serialized answer to stdout with no extra text.
Difficulty: MEDIUM. Variant: 14. 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 medium difficulty.
The signed-in workspace provides the tools required by the round, such as recording,