pyPython Practice LabFrom first print to final round
TOPIC 17 OF 18

Top Company Graphs and Union-Find Python practice problems

Solve connectivity, dependency, weighted-path, and ordering problems with graph algorithms.

20 exercises8+ conceptsBeginner → interview context
Start this topic
WHAT YOU WILL PRACTISE

Core concepts

Count connected components with union-findFind a redundant graph edgeCheck if courses can be completedClone an undirected graphMerge accounts by shared emailFind a word-ladder lengthEvaluate division queriesFind network delay time
REUSABLE THINKING

Problem-solving patterns

  • Model vertices and edges → select traversal or shortest-path strategy
INTERVIEW SIGNALS

Reported company tags

GoogleAmazonMicrosoftMetaUber
Community-reported tags are guidance, not guarantees.
ORDERED PRACTICE

All 20 problems in this topic

Work from top to bottom to build the concept gradually.

  1. #321
    Count connected components with union-find: Two graph components

    Count groups of vertices connected by undirected edges.

    Company MediumPremium
  2. #322
    Count connected components with union-find: No edges

    Every isolated vertex forms its own component.

    Company MediumPremium
  3. #323
    Find a redundant graph edge: Triangle cycle

    Find the final edge that closes a cycle in an almost-tree graph.

    Company MediumPremium
  4. #324
    Find a redundant graph edge: Longer cycle

    Detect the edge that reconnects vertices already joined through another route.

    Company MediumPremium
  5. #325
    Check if courses can be completed: Acyclic prerequisites

    Determine that every course can be completed in some valid order.

    Company MediumPremium
  6. #326
    Check if courses can be completed: Circular prerequisites

    Reject a plan where two courses depend on each other.

    Company MediumPremium
  7. #327
    Clone an undirected graph: Connected graph clone

    Deep-copy an undirected graph and print the clone's adjacency list.

    Company MediumPremium
  8. #328
    Clone an undirected graph: Include isolated node

    Preserve a vertex even when it has no neighbors.

    Company MediumPremium
  9. #329
    Merge accounts by shared email: Shared email merge

    Combine account rows that belong to the same person through a shared email.

    Company MediumPremium
  10. #330
    Merge accounts by shared email: No shared emails

    Keep every account separate when no email appears twice.

    Company MediumPremium
  11. #331
    Find a word-ladder length: Reachable transformation

    Find the shortest valid sequence from hit to cog.

    Company HardPremium
  12. #332
    Find a word-ladder length: Missing destination

    Return zero when the destination is absent from the dictionary.

    Company HardPremium
  13. #333
    Evaluate division queries: Connected ratios

    Evaluate direct, inverse, chained, and unknown division queries.

    Company MediumPremium
  14. #334
    Evaluate division queries: Disconnected variables

    Return -1 when no path connects two known variables.

    Company MediumPremium
  15. #335
    Find network delay time: All nodes reached

    Find how long a signal takes to reach every node in a weighted network.

    Company MediumPremium
  16. #336
    Find network delay time: Unreachable node

    Return -1 when at least one node cannot receive the signal.

    Company MediumPremium
  17. #337
    Find cheapest flight with stop limit: Cheaper one-stop route

    Choose a cheaper route that uses one allowed stop.

    Company MediumPremium
  18. #338
    Find cheapest flight with stop limit: Stop limit blocks route

    Return the direct price when a cheaper multi-edge route uses too many stops.

    Company MediumPremium
  19. #339
    Infer an alien alphabet: Valid alien order

    Infer one deterministic character order from a sorted alien dictionary.

    Company HardPremium
  20. #340
    Infer an alien alphabet: Invalid prefix order

    Reject a longer word that incorrectly appears before its exact prefix.

    Company HardPremium