Skip to content
LEETFLIX

method

BFS — animated LeetCode walkthroughs

LeetCode problems solved with BFS. Browse the complete tag, then watch the algorithm move — step-by-step animation, Python and Go.

260 problems · 204 animated · 56 locked

Start with a walkthrough

Full BFS index

  1. 100Same TreeWatch
  2. 101Symmetric TreeWatch
  3. 102Binary Tree Level Order TraversalWatch
  4. 103Binary Tree Zigzag Level Order TraversalWatch
  5. 104Maximum Depth of Binary TreeWatch
  6. 107Binary Tree Level Order Traversal IIWatch
  7. 111Minimum Depth of Binary TreeWatch
  8. 112Path SumWatch
  9. 116Populating Next Right Pointers in Each NodeWatch
  10. 117Populating Next Right Pointers in Each Node IIWatch
  11. 126Word Ladder IIWatch
  12. 127Word LadderWatch
  13. 130Surrounded RegionsWatch
  14. 133Clone GraphWatch
  15. 199Binary Tree Right Side ViewWatch
  16. 200Number of IslandsWatch
  17. 207Course ScheduleWatch
  18. 210Course Schedule IIWatch
  19. 226Invert Binary TreeWatch
  20. 261Graph Valid TreeLocked
  21. 269Alien DictionaryLocked
  22. 279Perfect SquaresWatch
  23. 286Walls and GatesLocked
  24. 297Serialize and Deserialize Binary TreeWatch
  25. 301Remove Invalid ParenthesesWatch
  26. 302Smallest Rectangle Enclosing Black PixelsLocked
  27. 310Minimum Height TreesWatch
  28. 314Binary Tree Vertical Order TraversalLocked
  29. 317Shortest Distance from All BuildingsLocked
  30. 322Coin ChangeWatch
  31. 323Number of Connected Components in an Undirected GraphLocked
  32. 329Longest Increasing Path in a MatrixWatch
  33. 339Nested List Weight SumLocked
  34. 364Nested List Weight Sum IILocked
  35. 365Water and Jug ProblemWatch
  36. 399Evaluate DivisionWatch
  37. 404Sum of Left LeavesWatch
  38. 407Trapping Rain Water IIWatch
  39. 417Pacific Atlantic Water FlowWatch
  40. 428Serialize and Deserialize N-ary TreeLocked
  41. 429N-ary Tree Level Order TraversalWatch
  42. 431Encode N-ary Tree to Binary TreeLocked
  43. 433Minimum Genetic MutationWatch
  44. 449Serialize and Deserialize BSTWatch
  45. 463Island PerimeterWatch
  46. 488Zuma GameWatch
  47. 490The MazeLocked
  48. 499The Maze IIILocked
  49. 505The Maze IILocked
  50. 513Find Bottom Left Tree ValueWatch
  51. 514Freedom TrailWatch
  52. 515Find Largest Value in Each Tree RowWatch
  53. 529MinesweeperWatch
  54. 530Minimum Absolute Difference in BSTWatch
  55. 54201 MatrixWatch
  56. 547Number of ProvincesWatch
  57. 559Maximum Depth of N-ary TreeWatch
  58. 582Kill ProcessLocked
  59. 617Merge Two Binary TreesWatch
  60. 623Add One Row to TreeWatch
  61. 637Average of Levels in Binary TreeWatch
  62. 653Two Sum IV - Input is a BSTWatch
  63. 655Print Binary TreeWatch
  64. 662Maximum Width of Binary TreeWatch
  65. 672Bulb Switcher IIWatch
  66. 675Cut Off Trees for Golf EventWatch
  67. 684Redundant ConnectionWatch
  68. 685Redundant Connection IIWatch
  69. 690Employee ImportanceWatch
  70. 694Number of Distinct IslandsLocked
  71. 695Max Area of IslandWatch
  72. 711Number of Distinct Islands IILocked
  73. 721Accounts MergeWatch
  74. 733Flood FillWatch
  75. 737Sentence Similarity IILocked
  76. 742Closest Leaf in a Binary TreeLocked
  77. 743Network Delay TimeWatch
  78. 749Contain VirusWatch
  79. 752Open the LockWatch
  80. 765Couples Holding HandsWatch
  81. 773Sliding PuzzleWatch
  82. 778Swim in Rising WaterWatch
  83. 783Minimum Distance Between BST NodesWatch
  84. 785Is Graph Bipartite?Watch
  85. 787Cheapest Flights Within K StopsWatch
  86. 797All Paths From Source to TargetWatch
  87. 802Find Eventual Safe StatesWatch
  88. 815Bus RoutesWatch
  89. 827Making A Large IslandWatch
  90. 839Similar String GroupsWatch
  91. 841Keys and RoomsWatch
  92. 847Shortest Path Visiting All NodesWatch
  93. 854K-Similar StringsWatch
  94. 863All Nodes Distance K in Binary TreeWatch
  95. 864Shortest Path to Get All KeysWatch
  96. 865Smallest Subtree with all the Deepest NodesWatch
  97. 886Possible BipartitionWatch
  98. 909Snakes and LaddersWatch
  99. 919Complete Binary Tree InserterWatch
  100. 924Minimize Malware SpreadWatch
  101. 928Minimize Malware Spread IIWatch
  102. 934Shortest BridgeWatch
  103. 958Check Completeness of a Binary TreeWatch
  104. 959Regions Cut By SlashesWatch
  105. 965Univalued Binary TreeWatch
  106. 967Numbers With Same Consecutive DifferencesWatch
  107. 987Vertical Order Traversal of a Binary TreeWatch
  108. 993Cousins in Binary TreeWatch
  109. 994Rotting OrangesWatch
  110. 1020Number of EnclavesWatch
  111. 1034Coloring A BorderWatch
  112. 1036Escape a Large MazeWatch
  113. 1042Flower Planting With No AdjacentWatch
  114. 1087Brace ExpansionLocked
  115. 1091Shortest Path in Binary MatrixWatch
  116. 1096Brace Expansion IIWatch
  117. 1102Path With Maximum Minimum ValueLocked
  118. 1123Lowest Common Ancestor of Deepest LeavesWatch
  119. 1129Shortest Path with Alternating ColorsWatch
  120. 1161Maximum Level Sum of a Binary TreeWatch
  121. 1162As Far from Land as PossibleWatch
  122. 1197Minimum Knight MovesLocked
  123. 1202Smallest String With SwapsWatch
  124. 1203Sort Items by Groups Respecting DependenciesWatch
  125. 1210Minimum Moves to Reach Target with RotationsWatch
  126. 1215Stepping NumbersLocked
  127. 1236Web CrawlerLocked
  128. 1242Web Crawler MultithreadedLocked
  129. 1245Tree DiameterLocked
  130. 1254Number of Closed IslandsWatch
  131. 1257Smallest Common RegionLocked
  132. 1261Find Elements in a Contaminated Binary TreeWatch
  133. 1263Minimum Moves to Move a Box to Their Target LocationWatch
  134. 1267Count Servers that CommunicateWatch
  135. 1273Delete Tree NodesLocked
  136. 1284Minimum Number of Flips to Convert Binary Matrix to Zero MatrixWatch
  137. 1293Shortest Path in a Grid with Obstacles EliminationWatch
  138. 1298Maximum Candies You Can Get from BoxesWatch
  139. 1302Deepest Leaves SumWatch
  140. 1306Jump Game IIIWatch
  141. 1311Get Watched Videos by Your FriendsWatch
  142. 1315Sum of Nodes with Even-Valued GrandparentWatch
  143. 1319Number of Operations to Make Network ConnectedWatch
  144. 1345Jump Game IVWatch
  145. 1361Validate Binary Tree NodesWatch
  146. 1368Minimum Cost to Make at Least One Valid Path in a GridWatch
  147. 1376Time Needed to Inform All EmployeesWatch
  148. 1377Frog Position After T SecondsWatch
  149. 1379Find a Corresponding Node of a Binary Tree in a Clone of That TreeWatch
  150. 1391Check if There is a Valid Path in a GridWatch
  151. 1430Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary TreeLocked
  152. 1443Minimum Time to Collect All Apples in a TreeWatch
  153. 1448Count Good Nodes in Binary TreeWatch
  154. 1457Pseudo-Palindromic Paths in a Binary TreeWatch
  155. 1462Course Schedule IVWatch
  156. 1466Reorder Routes to Make All Paths Lead to the City ZeroWatch
  157. 1469Find All The Lonely NodesLocked
  158. 1483Kth Ancestor of a Tree NodeWatch
  159. 1485Clone Binary Tree With Random PointerLocked
  160. 1490Clone N-ary TreeLocked
  161. 1519Number of Nodes in the Sub-Tree With the Same LabelWatch
  162. 1559Detect Cycles in 2D GridWatch
  163. 1568Minimum Number of Days to Disconnect IslandWatch
  164. 1602Find Nearest Right Node in Binary TreeLocked
  165. 1609Even Odd TreeWatch
  166. 1625Lexicographically Smallest String After Applying OperationsWatch
  167. 1631Path With Minimum EffortWatch
  168. 1654Minimum Jumps to Reach HomeWatch
  169. 1660Correct a Binary TreeLocked
  170. 1730Shortest Path to Get FoodLocked
  171. 1740Find Distance in a Binary TreeLocked
  172. 1765Map of Highest PeakWatch
  173. 1778Shortest Path in a Hidden GridLocked
  174. 1810Minimum Path Cost in a Hidden GridLocked
  175. 1905Count Sub IslandsWatch
  176. 1926Nearest Exit from Entrance in MazeWatch
  177. 1970Last Day Where You Can Still CrossWatch
  178. 1971Find if Path Exists in GraphWatch
  179. 1992Find All Groups of FarmlandWatch
  180. 1993Operations on TreeWatch
  181. 2039The Time When the Network Becomes IdleWatch
  182. 2045Second Minimum Time to Reach DestinationWatch
  183. 2059Minimum Operations to Convert NumberWatch
  184. 2092Find All People With SecretWatch
  185. 2101Detonate the Maximum BombsWatch
  186. 2146K Highest Ranked Items Within a Price RangeWatch
  187. 2174Remove All Ones With Row and Column Flips IILocked
  188. 2192All Ancestors of a Node in a Directed Acyclic GraphWatch
  189. 2204Distance to a Cycle in Undirected GraphLocked
  190. 2258Escape the Spreading FireWatch
  191. 2277Closest Node to Path in TreeLocked
  192. 2290Minimum Obstacle Removal to Reach CornerWatch
  193. 2316Count Unreachable Pairs of Nodes in an Undirected GraphWatch
  194. 2328Number of Increasing Paths in a GridWatch
  195. 2360Longest Cycle in a GraphWatch
  196. 2368Reachable Nodes With RestrictionsWatch
  197. 2385Amount of Time for Binary Tree to Be InfectedWatch
  198. 2415Reverse Odd Levels of Binary TreeWatch
  199. 2445Number of Nodes With Value OneLocked
  200. 2458Height of Binary Tree After Subtree Removal QueriesWatch
  201. 2467Most Profitable Path in a TreeWatch
  202. 2471Minimum Number of Operations to Sort a Binary Tree by LevelWatch
  203. 2477Minimum Fuel Cost to Report to the CapitalWatch
  204. 2492Minimum Score of a Path Between Two CitiesWatch
  205. 2493Divide Nodes Into the Maximum Number of GroupsWatch
  206. 2503Maximum Number of Points From Grid QueriesWatch
  207. 2556Disconnect Path in a Binary Matrix by at Most One FlipWatch
  208. 2577Minimum Time to Visit a Cell In a GridWatch
  209. 2583Kth Largest Sum in a Binary TreeWatch
  210. 2596Check Knight Tour ConfigurationWatch
  211. 2608Shortest Cycle in a GraphWatch
  212. 2612Minimum Reverse OperationsWatch
  213. 2617Minimum Number of Visited Cells in a GridWatch
  214. 2641Cousins in Binary Tree IIWatch
  215. 2658Maximum Number of Fish in a GridWatch
  216. 2685Count the Number of Complete ComponentsWatch
  217. 2773Height of Special Binary TreeLocked
  218. 2812Find the Safest Path in a GridWatch
  219. 2814Minimum Time Takes to Reach Destination Without DrowningLocked
  220. 2852Sum of Remoteness of All CellsLocked
  221. 2858Minimum Edge Reversals So Every Node Is ReachableWatch
  222. 2998Minimum Number of Operations to Make X and Y EqualWatch
  223. 3015Count the Number of Houses at a Certain Distance IWatch
  224. 3123Find Edges in Shortest PathsWatch
  225. 3141Maximum Hamming DistancesLocked
  226. 3157Find the Level of Tree with Minimum SumLocked
  227. 3203Find Minimum Diameter After Merging Two TreesWatch
  228. 3235Check if the Rectangle Corner Is ReachableWatch
  229. 3243Shortest Distance After Road Addition Queries IWatch
  230. 3283Maximum Number of Moves to Kill All PawnsWatch
  231. 3286Find a Safe Walk Through a GridWatch
  232. 3310Remove Methods From ProjectWatch
  233. 3372Maximize the Number of Target Nodes After Connecting Trees IWatch
  234. 3373Maximize the Number of Target Nodes After Connecting Trees IIWatch
  235. 3376Minimum Time to Break Locks IWatch
  236. 3383Minimum Runes to Add to Cast SpellLocked
  237. 3385Minimum Time to Break Locks IILocked
  238. 3387Maximize Amount After Two Days of ConversionsWatch
  239. 3419Minimize the Maximum Edge Weight of GraphWatch
  240. 3481Apply SubstitutionsLocked
  241. 3493Properties GraphWatch
  242. 3528Unit Conversion IWatch
  243. 3535Unit Conversion IILocked
  244. 3552Grid Teleportation TraversalWatch
  245. 3568Minimum Moves to Clean the ClassroomWatch
  246. 3607Power Grid MaintenanceWatch
  247. 3619Count Islands With Total Value Divisible by KWatch
  248. 3629Minimum Jumps to Reach End via Prime TeleportationWatch
  249. 3666Minimum Operations to Equalize Binary StringWatch
  250. 3690Split and Merge Array TransformationWatch
  251. 3710Maximum Partition FactorWatch
  252. 3787Find Diameter Endpoints of a TreeLocked
  253. 3807Minimum Cost to Repair Edges to Traverse a GraphLocked
  254. 3820Pythagorean Distance Nodes in a TreeWatch
  255. 3831Median of a Binary Search Tree LevelLocked
  256. 3902Zigzag Level Sum of Binary TreeLocked
  257. 3905Multi Source Flood FillWatch
  258. 3910Count Connected Subgraphs with Even Node SumWatch
  259. 3924Minimum Threshold Path With Limited Heavy EdgesWatch
  260. 3991Sort Array Using Prefix ReversalsLocked