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
- 100Same TreeWatch
- 101Symmetric TreeWatch
- 102Binary Tree Level Order TraversalWatch
- 103Binary Tree Zigzag Level Order TraversalWatch
- 104Maximum Depth of Binary TreeWatch
- 107Binary Tree Level Order Traversal IIWatch
- 111Minimum Depth of Binary TreeWatch
- 112Path SumWatch
- 116Populating Next Right Pointers in Each NodeWatch
- 117Populating Next Right Pointers in Each Node IIWatch
- 126Word Ladder IIWatch
- 127Word LadderWatch
- 130Surrounded RegionsWatch
- 133Clone GraphWatch
- 199Binary Tree Right Side ViewWatch
- 200Number of IslandsWatch
- 207Course ScheduleWatch
- 210Course Schedule IIWatch
- 226Invert Binary TreeWatch
- 261Graph Valid TreeLocked
- 269Alien DictionaryLocked
- 279Perfect SquaresWatch
- 286Walls and GatesLocked
- 297Serialize and Deserialize Binary TreeWatch
- 301Remove Invalid ParenthesesWatch
- 302Smallest Rectangle Enclosing Black PixelsLocked
- 310Minimum Height TreesWatch
- 314Binary Tree Vertical Order TraversalLocked
- 317Shortest Distance from All BuildingsLocked
- 322Coin ChangeWatch
- 323Number of Connected Components in an Undirected GraphLocked
- 329Longest Increasing Path in a MatrixWatch
- 339Nested List Weight SumLocked
- 364Nested List Weight Sum IILocked
- 365Water and Jug ProblemWatch
- 399Evaluate DivisionWatch
- 404Sum of Left LeavesWatch
- 407Trapping Rain Water IIWatch
- 417Pacific Atlantic Water FlowWatch
- 428Serialize and Deserialize N-ary TreeLocked
- 429N-ary Tree Level Order TraversalWatch
- 431Encode N-ary Tree to Binary TreeLocked
- 433Minimum Genetic MutationWatch
- 449Serialize and Deserialize BSTWatch
- 463Island PerimeterWatch
- 488Zuma GameWatch
- 490The MazeLocked
- 499The Maze IIILocked
- 505The Maze IILocked
- 513Find Bottom Left Tree ValueWatch
- 514Freedom TrailWatch
- 515Find Largest Value in Each Tree RowWatch
- 529MinesweeperWatch
- 530Minimum Absolute Difference in BSTWatch
- 54201 MatrixWatch
- 547Number of ProvincesWatch
- 559Maximum Depth of N-ary TreeWatch
- 582Kill ProcessLocked
- 617Merge Two Binary TreesWatch
- 623Add One Row to TreeWatch
- 637Average of Levels in Binary TreeWatch
- 653Two Sum IV - Input is a BSTWatch
- 655Print Binary TreeWatch
- 662Maximum Width of Binary TreeWatch
- 672Bulb Switcher IIWatch
- 675Cut Off Trees for Golf EventWatch
- 684Redundant ConnectionWatch
- 685Redundant Connection IIWatch
- 690Employee ImportanceWatch
- 694Number of Distinct IslandsLocked
- 695Max Area of IslandWatch
- 711Number of Distinct Islands IILocked
- 721Accounts MergeWatch
- 733Flood FillWatch
- 737Sentence Similarity IILocked
- 742Closest Leaf in a Binary TreeLocked
- 743Network Delay TimeWatch
- 749Contain VirusWatch
- 752Open the LockWatch
- 765Couples Holding HandsWatch
- 773Sliding PuzzleWatch
- 778Swim in Rising WaterWatch
- 783Minimum Distance Between BST NodesWatch
- 785Is Graph Bipartite?Watch
- 787Cheapest Flights Within K StopsWatch
- 797All Paths From Source to TargetWatch
- 802Find Eventual Safe StatesWatch
- 815Bus RoutesWatch
- 827Making A Large IslandWatch
- 839Similar String GroupsWatch
- 841Keys and RoomsWatch
- 847Shortest Path Visiting All NodesWatch
- 854K-Similar StringsWatch
- 863All Nodes Distance K in Binary TreeWatch
- 864Shortest Path to Get All KeysWatch
- 865Smallest Subtree with all the Deepest NodesWatch
- 886Possible BipartitionWatch
- 909Snakes and LaddersWatch
- 919Complete Binary Tree InserterWatch
- 924Minimize Malware SpreadWatch
- 928Minimize Malware Spread IIWatch
- 934Shortest BridgeWatch
- 958Check Completeness of a Binary TreeWatch
- 959Regions Cut By SlashesWatch
- 965Univalued Binary TreeWatch
- 967Numbers With Same Consecutive DifferencesWatch
- 987Vertical Order Traversal of a Binary TreeWatch
- 993Cousins in Binary TreeWatch
- 994Rotting OrangesWatch
- 1020Number of EnclavesWatch
- 1034Coloring A BorderWatch
- 1036Escape a Large MazeWatch
- 1042Flower Planting With No AdjacentWatch
- 1087Brace ExpansionLocked
- 1091Shortest Path in Binary MatrixWatch
- 1096Brace Expansion IIWatch
- 1102Path With Maximum Minimum ValueLocked
- 1123Lowest Common Ancestor of Deepest LeavesWatch
- 1129Shortest Path with Alternating ColorsWatch
- 1161Maximum Level Sum of a Binary TreeWatch
- 1162As Far from Land as PossibleWatch
- 1197Minimum Knight MovesLocked
- 1202Smallest String With SwapsWatch
- 1203Sort Items by Groups Respecting DependenciesWatch
- 1210Minimum Moves to Reach Target with RotationsWatch
- 1215Stepping NumbersLocked
- 1236Web CrawlerLocked
- 1242Web Crawler MultithreadedLocked
- 1245Tree DiameterLocked
- 1254Number of Closed IslandsWatch
- 1257Smallest Common RegionLocked
- 1261Find Elements in a Contaminated Binary TreeWatch
- 1263Minimum Moves to Move a Box to Their Target LocationWatch
- 1267Count Servers that CommunicateWatch
- 1273Delete Tree NodesLocked
- 1284Minimum Number of Flips to Convert Binary Matrix to Zero MatrixWatch
- 1293Shortest Path in a Grid with Obstacles EliminationWatch
- 1298Maximum Candies You Can Get from BoxesWatch
- 1302Deepest Leaves SumWatch
- 1306Jump Game IIIWatch
- 1311Get Watched Videos by Your FriendsWatch
- 1315Sum of Nodes with Even-Valued GrandparentWatch
- 1319Number of Operations to Make Network ConnectedWatch
- 1345Jump Game IVWatch
- 1361Validate Binary Tree NodesWatch
- 1368Minimum Cost to Make at Least One Valid Path in a GridWatch
- 1376Time Needed to Inform All EmployeesWatch
- 1377Frog Position After T SecondsWatch
- 1379Find a Corresponding Node of a Binary Tree in a Clone of That TreeWatch
- 1391Check if There is a Valid Path in a GridWatch
- 1430Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary TreeLocked
- 1443Minimum Time to Collect All Apples in a TreeWatch
- 1448Count Good Nodes in Binary TreeWatch
- 1457Pseudo-Palindromic Paths in a Binary TreeWatch
- 1462Course Schedule IVWatch
- 1466Reorder Routes to Make All Paths Lead to the City ZeroWatch
- 1469Find All The Lonely NodesLocked
- 1483Kth Ancestor of a Tree NodeWatch
- 1485Clone Binary Tree With Random PointerLocked
- 1490Clone N-ary TreeLocked
- 1519Number of Nodes in the Sub-Tree With the Same LabelWatch
- 1559Detect Cycles in 2D GridWatch
- 1568Minimum Number of Days to Disconnect IslandWatch
- 1602Find Nearest Right Node in Binary TreeLocked
- 1609Even Odd TreeWatch
- 1625Lexicographically Smallest String After Applying OperationsWatch
- 1631Path With Minimum EffortWatch
- 1654Minimum Jumps to Reach HomeWatch
- 1660Correct a Binary TreeLocked
- 1730Shortest Path to Get FoodLocked
- 1740Find Distance in a Binary TreeLocked
- 1765Map of Highest PeakWatch
- 1778Shortest Path in a Hidden GridLocked
- 1810Minimum Path Cost in a Hidden GridLocked
- 1905Count Sub IslandsWatch
- 1926Nearest Exit from Entrance in MazeWatch
- 1970Last Day Where You Can Still CrossWatch
- 1971Find if Path Exists in GraphWatch
- 1992Find All Groups of FarmlandWatch
- 1993Operations on TreeWatch
- 2039The Time When the Network Becomes IdleWatch
- 2045Second Minimum Time to Reach DestinationWatch
- 2059Minimum Operations to Convert NumberWatch
- 2092Find All People With SecretWatch
- 2101Detonate the Maximum BombsWatch
- 2146K Highest Ranked Items Within a Price RangeWatch
- 2174Remove All Ones With Row and Column Flips IILocked
- 2192All Ancestors of a Node in a Directed Acyclic GraphWatch
- 2204Distance to a Cycle in Undirected GraphLocked
- 2258Escape the Spreading FireWatch
- 2277Closest Node to Path in TreeLocked
- 2290Minimum Obstacle Removal to Reach CornerWatch
- 2316Count Unreachable Pairs of Nodes in an Undirected GraphWatch
- 2328Number of Increasing Paths in a GridWatch
- 2360Longest Cycle in a GraphWatch
- 2368Reachable Nodes With RestrictionsWatch
- 2385Amount of Time for Binary Tree to Be InfectedWatch
- 2415Reverse Odd Levels of Binary TreeWatch
- 2445Number of Nodes With Value OneLocked
- 2458Height of Binary Tree After Subtree Removal QueriesWatch
- 2467Most Profitable Path in a TreeWatch
- 2471Minimum Number of Operations to Sort a Binary Tree by LevelWatch
- 2477Minimum Fuel Cost to Report to the CapitalWatch
- 2492Minimum Score of a Path Between Two CitiesWatch
- 2493Divide Nodes Into the Maximum Number of GroupsWatch
- 2503Maximum Number of Points From Grid QueriesWatch
- 2556Disconnect Path in a Binary Matrix by at Most One FlipWatch
- 2577Minimum Time to Visit a Cell In a GridWatch
- 2583Kth Largest Sum in a Binary TreeWatch
- 2596Check Knight Tour ConfigurationWatch
- 2608Shortest Cycle in a GraphWatch
- 2612Minimum Reverse OperationsWatch
- 2617Minimum Number of Visited Cells in a GridWatch
- 2641Cousins in Binary Tree IIWatch
- 2658Maximum Number of Fish in a GridWatch
- 2685Count the Number of Complete ComponentsWatch
- 2773Height of Special Binary TreeLocked
- 2812Find the Safest Path in a GridWatch
- 2814Minimum Time Takes to Reach Destination Without DrowningLocked
- 2852Sum of Remoteness of All CellsLocked
- 2858Minimum Edge Reversals So Every Node Is ReachableWatch
- 2998Minimum Number of Operations to Make X and Y EqualWatch
- 3015Count the Number of Houses at a Certain Distance IWatch
- 3123Find Edges in Shortest PathsWatch
- 3141Maximum Hamming DistancesLocked
- 3157Find the Level of Tree with Minimum SumLocked
- 3203Find Minimum Diameter After Merging Two TreesWatch
- 3235Check if the Rectangle Corner Is ReachableWatch
- 3243Shortest Distance After Road Addition Queries IWatch
- 3283Maximum Number of Moves to Kill All PawnsWatch
- 3286Find a Safe Walk Through a GridWatch
- 3310Remove Methods From ProjectWatch
- 3372Maximize the Number of Target Nodes After Connecting Trees IWatch
- 3373Maximize the Number of Target Nodes After Connecting Trees IIWatch
- 3376Minimum Time to Break Locks IWatch
- 3383Minimum Runes to Add to Cast SpellLocked
- 3385Minimum Time to Break Locks IILocked
- 3387Maximize Amount After Two Days of ConversionsWatch
- 3419Minimize the Maximum Edge Weight of GraphWatch
- 3481Apply SubstitutionsLocked
- 3493Properties GraphWatch
- 3528Unit Conversion IWatch
- 3535Unit Conversion IILocked
- 3552Grid Teleportation TraversalWatch
- 3568Minimum Moves to Clean the ClassroomWatch
- 3607Power Grid MaintenanceWatch
- 3619Count Islands With Total Value Divisible by KWatch
- 3629Minimum Jumps to Reach End via Prime TeleportationWatch
- 3666Minimum Operations to Equalize Binary StringWatch
- 3690Split and Merge Array TransformationWatch
- 3710Maximum Partition FactorWatch
- 3787Find Diameter Endpoints of a TreeLocked
- 3807Minimum Cost to Repair Edges to Traverse a GraphLocked
- 3820Pythagorean Distance Nodes in a TreeWatch
- 3831Median of a Binary Search Tree LevelLocked
- 3902Zigzag Level Sum of Binary TreeLocked
- 3905Multi Source Flood FillWatch
- 3910Count Connected Subgraphs with Even Node SumWatch
- 3924Minimum Threshold Path With Limited Heavy EdgesWatch
- 3991Sort Array Using Prefix ReversalsLocked