Graphs & Matrices Interview Questions & Solutions
27 solutions ยท 6 Easy ยท 18 Medium ยท 3 Hard
Graph problems intimidate candidates until they notice the pattern: the vast majority are solved by the same two traversals, BFS and DFS. The skill isn't memorizing exotic algorithms โ it's modeling the problem as a graph, picking the right traversal, and tracking visited state so you don't loop forever. A huge share of "matrix" questions are really graph questions where each cell is a node and its four neighbors are edges.
These solutions make that modeling explicit. You'll cover grid traversal (number of islands, flood fill, rotting oranges), connected components and union-find, cycle detection and topological sort for dependency problems, and shortest-path problems where BFS on an unweighted graph is exactly the right tool. We're careful about the details that actually sink submissions: marking cells visited correctly, handling boundaries, and choosing BFS when you need the shortest number of steps versus DFS when you just need reachability. Once this pattern lands, a whole tier of "hard" interview problems becomes approachable.
- Find if Path Exists in GraphEasy
- Find the Town JudgeEasy
- Flood FillEasy
- Island PerimeterEasy
- Matrix Diagonal SumEasy
- Reshape the MatrixEasy
- 01 MatrixMedium
- All Paths From Source to TargetMedium
- Cheapest Flights Within K StopsMedium
- Clone GraphMedium
- Course ScheduleMedium
- Evaluate DivisionMedium
- Game of LifeMedium
- Is Graph Bipartite?Medium
- Max Area of IslandMedium
- MinesweeperMedium
- Minimum Height TreesMedium
- Number of IslandsMedium
- Number of ProvincesMedium
- Rotate ImageMedium
- Rotting OrangesMedium
- Snakes and LaddersMedium
- Spiral MatrixMedium
- Surrounded RegionsMedium
- Longest Increasing Path in a MatrixHard
- Redundant Connection IIHard
- Word LadderHard
Practice Graphs & Matrices the right way
SkillFlow serves you Graphs & Matrices problems matched to your level, times you like a real interview, and tracks your proficiency as it climbs. Free.
Start practicing free โ