Lesson overview · Free interview practice

Graphs

Learn about graph representations and graph traversal methods.

Topics in the full lesson
  • Concept and Use Cases
  • Types of Graphs
  • When to Use
  • Time and Space Complexity
  • Graph Representation
  • Graph Operations and Methods
  • Practical Tips and Tricks
  • Common Gotchas
  • Advanced Topics
  • Graph Algorithms
  • Interview Tips and Tricks
  • Common Mistakes

Try the free interview questions

Work through a question before revealing its explanation. These questions and answers are free; Premium adds the full lesson walkthrough, examples and implementation detail.

CodingMedium

Clone Graph

Question

Implement an algorithm to create a deep copy of a graph, including all nodes and edges, while preserving the original structure.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Question

There are n cities connected by flights, where flights[i] = [from, to, price]. Given src, dst, and an integer k, return the cheapest total price to travel from src to dst using at most k stops (intermediate cities), or -1 if there is no such route.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

CodingMedium

Rotting Oranges

Question

You are given an m x n grid where each cell is 0 (empty), 1 (a fresh orange), or 2 (a rotten orange). Every minute, any fresh orange that is 4-directionally adjacent to a rotten orange becomes rotten. Return the minimum number of minutes that must elapse until no cell has a fresh orange, or -1 if this is impossible.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

CodingMedium

Evaluate Division

Question

You are given a list of division equations. Each pair equations[i] = [A, B] with the corresponding values[i] = v encodes the relation A / B = v. For each query [C, D], compute C / D using whatever chain of equations is needed; if it cannot be derived, return -1.0. Solve by modeling variables as nodes in a directed weighted graph and traversing (BFS/DFS) to compute query ratios.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Explore the full Graphs material

Premium includes the complete lessons and implementation references. Free practice questions remain available without a subscription.

All course tracks & premium content
From basics to advanced masterclasses
Built for JS/TS developers like you
Real-world tips & common pitfalls
Upgrade to Premium