CodeMosa

Master LeetCode Patterns

5 Problems

Dijkstra's Algorithm Practice Problems

Weighted shortest paths on graphs/grids with priority queue; includes 0-1 BFS alternatives where applicable.

Back to Collections

Relevant Patterns

#
Study these pattern guides before tackling the problems. Understanding the core concepts will help you solve them more efficiently.

Practice Problems

#
Show 2 hints
  • Run Dijkstra from source; answer is max dist or -1 if unreachable.
  • Skip stale pops; store adjacency as (to, weight).
Show 2 hints
  • Treat edge weight as abs height diff; use Dijkstra or binary search + BFS.
  • Grid neighbors 4‑dir; skip stale queue entries.
Show 2 hints
  • Run multi‑source Dijkstra/Floyd–Warshall; count reachable within threshold.
  • Tie‑break by city index descending.
Show 2 hints
  • Dijkstra where cost is max(cell value along path).
  • Alternatively binary search threshold + BFS.
Show 2 hints
  • Dijkstra on expanded edges budget; count reached subdivided nodes using remaining moves.
  • Careful accounting to avoid double counting.

Track Your Progress

Mark problems as complete as you solve them. Come back anytime to continue where you left off.