Top Company Graphs and Union-Find Python practice problems
Solve connectivity, dependency, weighted-path, and ordering problems with graph algorithms.
Core concepts
Problem-solving patterns
- Model vertices and edges → select traversal or shortest-path strategy
Reported company tags
All 20 problems in this topic
Work from top to bottom to build the concept gradually.
- #321Count connected components with union-find: Two graph componentsCompany MediumPremium
Count groups of vertices connected by undirected edges.
- #322Count connected components with union-find: No edgesCompany MediumPremium
Every isolated vertex forms its own component.
- #323Find a redundant graph edge: Triangle cycleCompany MediumPremium
Find the final edge that closes a cycle in an almost-tree graph.
- #324Find a redundant graph edge: Longer cycleCompany MediumPremium
Detect the edge that reconnects vertices already joined through another route.
- #325Check if courses can be completed: Acyclic prerequisitesCompany MediumPremium
Determine that every course can be completed in some valid order.
- #326Check if courses can be completed: Circular prerequisitesCompany MediumPremium
Reject a plan where two courses depend on each other.
- #327Clone an undirected graph: Connected graph cloneCompany MediumPremium
Deep-copy an undirected graph and print the clone's adjacency list.
- #328Clone an undirected graph: Include isolated nodeCompany MediumPremium
Preserve a vertex even when it has no neighbors.
- #329Merge accounts by shared email: Shared email mergeCompany MediumPremium
Combine account rows that belong to the same person through a shared email.
- #330Merge accounts by shared email: No shared emailsCompany MediumPremium
Keep every account separate when no email appears twice.
- #331Find a word-ladder length: Reachable transformationCompany HardPremium
Find the shortest valid sequence from hit to cog.
- #332Find a word-ladder length: Missing destinationCompany HardPremium
Return zero when the destination is absent from the dictionary.
- #333Evaluate division queries: Connected ratiosCompany MediumPremium
Evaluate direct, inverse, chained, and unknown division queries.
- #334Evaluate division queries: Disconnected variablesCompany MediumPremium
Return -1 when no path connects two known variables.
- #335Find network delay time: All nodes reachedCompany MediumPremium
Find how long a signal takes to reach every node in a weighted network.
- #336Find network delay time: Unreachable nodeCompany MediumPremium
Return -1 when at least one node cannot receive the signal.
- #337Find cheapest flight with stop limit: Cheaper one-stop routeCompany MediumPremium
Choose a cheaper route that uses one allowed stop.
- #338Find cheapest flight with stop limit: Stop limit blocks routeCompany MediumPremium
Return the direct price when a cheaper multi-edge route uses too many stops.
- #339Infer an alien alphabet: Valid alien orderCompany HardPremium
Infer one deterministic character order from a sorted alien dictionary.
- #340Infer an alien alphabet: Invalid prefix orderCompany HardPremium
Reject a longer word that incorrectly appears before its exact prefix.