Skip to content
QuizMaker logoQuizMaker
Activity
DSA Interview Patterns Roadmap

No lessons available

CONTENTS

Dijkstra and Shortest Path

Weighted shortest paths, constrained stops, probability paths, and grid costs.

DSA Interview Patterns Roadmap
Shortest Path, MST and Union Find
dsa
coding interview
+5
May 29, 2026
20
A

Learning Outcome

Weighted shortest paths, constrained stops, probability paths, and grid costs.

Pattern Recognition

ItemDetail
Core signalA known interview family appears and the constraints reward the standard pattern.
Use whenDijkstra is BFS with a priority queue when edges have non-uniform non-negative cost.
Avoid whenThe required invariant is not monotonic or the input constraints point to a simpler direct scan.

Intuition

Dijkstra is BFS with a priority queue when edges have non-uniform non-negative cost.

Exact Practice Question Names

  • Network Delay Time
  • Path with Maximum Probability
  • Cheapest Flights Within K Stops
  • Minimum Obstacle Removal to Reach Corner
  • The Maze II

Interview Approach

  1. Name the exact family.
  2. Write the invariant or state.
  3. Pick the standard container or recurrence.
  4. Dry-run the smallest example.
  5. State complexity and one follow-up.

Pseudocode

identify pattern
initialize state/container
for each input unit:
  update state safely
  update answer when invariant is valid
return answer

Sample Dry Run

Take the smallest Dijkstra and Shortest Path example, track the state after every operation, and verify the final answer before coding.

Edge Cases

  • Empty or single-item input
  • Duplicate values
  • Boundary constraints
  • Large values requiring long/int64

Common Mistakes

  • Memorizing code without naming the invariant
  • Skipping the brute-force baseline
  • Not explaining why the optimized approach is correct

Complexity

ItemDetail
Expected timeUsually O(n log n), O(V + E), or states times transitions depending on the family.
Expected spaceUsually O(n), O(V + E), or number of DP states.

Java, C++ and Python Notes

  • Java: prefer explicit classes and clear helper methods over clever one-liners.
  • C++: use vector, unordered_map, set, priority_queue, and long long when sums can grow.
  • Python: keep state readable with dict, set, deque, heapq, and lru_cache where appropriate.

Quick Revision Checklist

  • Name the pattern before coding.
  • State the invariant or DP state in one sentence.
  • Dry-run the smallest non-trivial example.
  • Close with time and space complexity.

Share this article

Share on TwitterShare on LinkedInShare on FacebookShare on WhatsAppShare on Email

Test your knowledge

Take a quick quiz based on this chapter.

mediumDSA Interview Patterns
Quiz: Dijkstra and Shortest Path
6 questions10 min

0 comments

Please login to comment.
No comments yet.
Lesson 2 of 7 in Shortest Path, MST and Union Find
Previous in Shortest Path, MST and Union Find
Union Find: Components, Islands and Connectivity
Next in Shortest Path, MST and Union Find
MST: Prim and Kruskal
Back to DSA Interview Patterns Roadmap
Back to moduleCategories