Breadth-First Search Problems
Master breadth-first search problems with AI-powered solutions. Get instant coding assistance during your technical interviews for all 170 problems in this category.
Total Problems: 170
Easy: 19
Medium: 104
Hard: 47
Showing 50 of 170 problems
Problems
Scroll within this area to browse all problems
#
Title
Difficulty
Breadth-First Search LeetCode Problems List
- 207. Course Schedule - Medium - Breadth-First SearchThere are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i... Topics: Depth-First Search, Breadth-First Search, Graph, Topological Sort
- 279. Perfect Squares - Medium - Breadth-First SearchGiven an integer n, return the least number of perfect square numbers that sum to n. A perfect square is an integer that is the square of an integer; ... Topics: Math, Dynamic Programming, Breadth-First Search
- 127. Word Ladder - Hard - Breadth-First SearchA transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk su... Topics: Hash Table, String, Breadth-First Search
- 226. Invert Binary Tree - Easy - Breadth-First SearchGiven the root of a binary tree, invert the tree, and return its root.... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 322. Coin Change - Medium - Breadth-First SearchYou are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return ... Topics: Array, Dynamic Programming, Breadth-First Search
- 200. Number of Islands - Medium - Breadth-First SearchGiven an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by wa... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 102. Binary Tree Level Order Traversal - Medium - Breadth-First SearchGiven the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).... Topics: Tree, Breadth-First Search, Binary Tree
- 721. Accounts Merge - Medium - Breadth-First SearchGiven a list of accounts where each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the el... Topics: Array, Hash Table, String, Depth-First Search, Breadth-First Search, Union Find, Sorting
- 803. Cheapest Flights Within K Stops - Medium - Breadth-First SearchThere are n cities connected by some number of flights. You are given an array flights where flights[i] = [fromi, toi, pricei] indicates that there is... Topics: Dynamic Programming, Depth-First Search, Breadth-First Search, Graph, Heap (Priority Queue), Shortest Path
- 733. Flood Fill - Easy - Breadth-First SearchYou are given an image represented by an m x n grid of integers image, where image[i][j] represents the pixel value of the image. You are also given t... Topics: Array, Depth-First Search, Breadth-First Search, Matrix
- 199. Binary Tree Right Side View - Medium - Breadth-First SearchGiven the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bot... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 210. Course Schedule II - Medium - Breadth-First SearchThere are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i... Topics: Depth-First Search, Breadth-First Search, Graph, Topological Sort
- 104. Maximum Depth of Binary Tree - Easy - Breadth-First SearchGiven the root of a binary tree, return its maximum depth. A binary tree's maximum depth is the number of nodes along the longest path from the root n... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 1029. Vertical Order Traversal of a Binary Tree - Hard - Breadth-First SearchGiven the root of a binary tree, calculate the vertical order traversal of the binary tree. For each node at position (row, col), its left and right c... Topics: Hash Table, Tree, Depth-First Search, Breadth-First Search, Sorting, Binary Tree
- 801. Is Graph Bipartite? - Medium - Breadth-First SearchThere is an undirected graph with n nodes, where each node is numbered between 0 and n - 1. You are given a 2D array graph, where graph[u] is an array... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 529. Minesweeper - Medium - Breadth-First SearchLet's play the minesweeper game (Wikipedia, online game)! You are given an m x n char matrix board representing the game board where: 'M' represents a... Topics: Array, Depth-First Search, Breadth-First Search, Matrix
- 1036. Rotting Oranges - Medium - Breadth-First SearchYou are given an m x n grid where each cell can have one of three values: 0 representing an empty cell, 1 representing a fresh orange, or 2 representi... Topics: Array, Breadth-First Search, Matrix
- 133. Clone Graph - Medium - Breadth-First SearchGiven a reference of a node in a connected undirected graph. Return a deep copy (clone) of the graph. Each node in the graph contains a value (int) an... Topics: Hash Table, Depth-First Search, Breadth-First Search, Graph
- 653. Two Sum IV - Input is a BST - Easy - Breadth-First SearchGiven the root of a binary search tree and an integer k, return true if there exist two elements in the BST such that their sum is equal to k, or fals... Topics: Hash Table, Two Pointers, Tree, Depth-First Search, Breadth-First Search, Binary Search Tree, Binary Tree
- 297. Serialize and Deserialize Binary Tree - Hard - Breadth-First SearchSerialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or ... Topics: String, Tree, Depth-First Search, Breadth-First Search, Design, Binary Tree
- 945. Snakes and Ladders - Medium - Breadth-First SearchYou are given an n x n integer matrix board where the cells are labeled from 1 to n2 in a Boustrophedon style starting from the bottom left of the boa... Topics: Array, Breadth-First Search, Matrix
- 787. Sliding Puzzle - Hard - Breadth-First SearchOn an 2 x 3 board, there are five tiles labeled from 1 to 5, and an empty square represented by 0. A move consists of choosing 0 and a 4-directionally... Topics: Array, Dynamic Programming, Backtracking, Breadth-First Search, Memoization, Matrix
- 329. Longest Increasing Path in a Matrix - Hard - Breadth-First SearchGiven an m x n integers matrix, return the length of the longest increasing path in matrix. From each cell, you can either move in four directions: le... Topics: Array, Dynamic Programming, Depth-First Search, Breadth-First Search, Graph, Topological Sort, Memoization, Matrix
- 301. Remove Invalid Parentheses - Hard - Breadth-First SearchGiven a string s that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid. Return a list... Topics: String, Backtracking, Breadth-First Search
- 103. Binary Tree Zigzag Level Order Traversal - Medium - Breadth-First SearchGiven the root of a binary tree, return the zigzag level order traversal of its nodes' values. (i.e., from left to right, then right to left for the n... Topics: Tree, Breadth-First Search, Binary Tree
- 753. Open the Lock - Medium - Breadth-First SearchYou have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rota... Topics: Array, Hash Table, String, Breadth-First Search
- 101. Symmetric Tree - Easy - Breadth-First SearchGiven the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 3613. Maximize Amount After Two Days of Conversions - Medium - Breadth-First SearchYou are given a string initialCurrency, and you start with 1.0 of initialCurrency. You are also given four arrays with currency pairs (strings) and ra... Topics: Array, String, Depth-First Search, Breadth-First Search, Graph
- 617. Merge Two Binary Trees - Easy - Breadth-First SearchYou are given two binary trees root1 and root2. Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped w... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 1428. Jump Game III - Medium - Breadth-First SearchGiven an array of non-negative integers arr, you are initially positioned at start index of the array. When you are at index i, you can jump to i + ar... Topics: Array, Depth-First Search, Breadth-First Search
- 111. Minimum Depth of Binary Tree - Easy - Breadth-First SearchGiven a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest l... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 854. Making A Large Island - Hard - Breadth-First SearchYou are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1. Return the size of the largest island in grid after applyi... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 794. Swim in Rising Water - Hard - Breadth-First SearchYou are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at that point (i, j). It starts raining, and water gra... Topics: Array, Binary Search, Depth-First Search, Breadth-First Search, Union Find, Heap (Priority Queue), Matrix
- 126. Word Ladder II - Hard - Breadth-First SearchA transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk su... Topics: Hash Table, String, Backtracking, Breadth-First Search
- 1447. Jump Game IV - Hard - Breadth-First SearchGiven an array of integers arr, you are initially positioned at the first index of the array. In one step you can jump from index i to index: i + 1 wh... Topics: Array, Hash Table, Breadth-First Search
- 433. Minimum Genetic Mutation - Medium - Breadth-First SearchA gene string can be represented by an 8-character long string, with choices from 'A', 'C', 'G', and 'T'. Suppose we need to investigate a mutation fr... Topics: Hash Table, String, Breadth-First Search
- 542. 01 Matrix - Medium - Breadth-First SearchGiven an m x n binary matrix mat, return the distance of the nearest 0 for each cell. The distance between two cells sharing a common edge is 1.... Topics: Array, Dynamic Programming, Breadth-First Search, Matrix
- 399. Evaluate Division - Medium - Breadth-First SearchYou are given an array of variable pairs equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] represent the equa... Topics: Array, String, Depth-First Search, Breadth-First Search, Union Find, Graph, Shortest Path
- 417. Pacific Atlantic Water Flow - Medium - Breadth-First SearchThere is an m x n rectangular island that borders both the Pacific Ocean and Atlantic Ocean. The Pacific Ocean touches the island's left and top edges... Topics: Array, Depth-First Search, Breadth-First Search, Matrix
- 3863. Power Grid Maintenance - Medium - Breadth-First SearchYou are given an integer c representing c power stations, each with a unique identifier id from 1 to c (1‑based indexing). These stations are intercon... Topics: Array, Hash Table, Depth-First Search, Breadth-First Search, Union Find, Graph, Heap (Priority Queue), Ordered Set
- 893. All Nodes Distance K in Binary Tree - Medium - Breadth-First SearchGiven the root of a binary tree, the value of a target node target, and an integer k, return an array of the values of all nodes that have a distance ... Topics: Hash Table, Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 1414. Shortest Path in a Grid with Obstacles Elimination - Hard - Breadth-First SearchYou are given an m x n integer matrix grid where each cell is either 0 (empty) or 1 (obstacle). You can move up, down, left, or right from and to an e... Topics: Array, Breadth-First Search, Matrix
- 1171. Shortest Path in Binary Matrix - Medium - Breadth-First SearchGiven an n x n binary matrix grid, return the length of the shortest clear path in the matrix. If there is no clear path, return -1. A clear path in a... Topics: Array, Breadth-First Search, Matrix
- 1558. Course Schedule IV - Medium - Breadth-First SearchThere are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i... Topics: Depth-First Search, Breadth-First Search, Graph, Topological Sort
- 116. Populating Next Right Pointers in Each Node - Medium - Breadth-First SearchYou are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following defin... Topics: Linked List, Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 744. Network Delay Time - Medium - Breadth-First SearchYou are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, vi, wi), w... Topics: Depth-First Search, Breadth-First Search, Graph, Heap (Priority Queue), Shortest Path
- 107. Binary Tree Level Order Traversal II - Medium - Breadth-First SearchGiven the root of a binary tree, return the bottom-up level order traversal of its nodes' values. (i.e., from left to right, level by level from leaf ... Topics: Tree, Breadth-First Search, Binary Tree
- 1106. Escape a Large Maze - Hard - Breadth-First SearchThere is a 1 million by 1 million grid on an XY-plane, and the coordinates of each grid square are (x, y). We start at the source = [sx, sy] square an... Topics: Array, Hash Table, Depth-First Search, Breadth-First Search
- 530. Minimum Absolute Difference in BST - Easy - Breadth-First SearchGiven the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree.... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Search Tree, Binary Tree
- 2035. Count Sub Islands - Medium - Breadth-First SearchYou are given two m x n binary matrices grid1 and grid2 containing only 0's (representing water) and 1's (representing land). An island is a group of ... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 684. Redundant Connection - Medium - Breadth-First SearchIn this problem, a tree is an undirected graph that is connected and has no cycles. You are given a graph that started as a tree with n nodes labeled ... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 513. Find Bottom Left Tree Value - Medium - Breadth-First SearchGiven the root of a binary tree, return the leftmost value in the last row of the tree.... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 971. Shortest Bridge - Medium - Breadth-First SearchYou are given an n x n binary matrix grid where 1 represents land and 0 represents water. An island is a 4-directionally connected group of 1's not co... Topics: Array, Depth-First Search, Breadth-First Search, Matrix
- 764. N-ary Tree Level Order Traversal - Medium - Breadth-First SearchGiven an n-ary tree, return the level order traversal of its nodes' values. Nary-Tree input serialization is represented in their level order traversa... Topics: Tree, Breadth-First Search
- 1380. Number of Closed Islands - Medium - Breadth-First SearchGiven a 2D grid consists of 0s (land) and 1s (water). An island is a maximal 4-directionally connected group of 0s and a closed island is an island t... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 1544. Count Good Nodes in Binary Tree - Medium - Breadth-First SearchGiven a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X. Return the ... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 2038. Nearest Exit from Entrance in Maze - Medium - Breadth-First SearchYou are given an m x n matrix maze (0-indexed) with empty cells (represented as '.') and walls (represented as '+'). You are also given the entrance o... Topics: Array, Breadth-First Search, Matrix
- 3823. Count Islands With Total Value Divisible by K - Medium - Breadth-First SearchYou are given an m x n matrix grid and a positive integer k. An island is a group of positive integers (representing land) that are 4-directionally co... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 1035. Cousins in Binary Tree - Easy - Breadth-First SearchGiven the root of a binary tree with unique values and the values of two different nodes of the tree x and y, return true if the nodes corresponding t... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 407. Trapping Rain Water II - Hard - Breadth-First SearchGiven an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after ... Topics: Array, Breadth-First Search, Heap (Priority Queue), Matrix
- 695. Max Area of Island - Medium - Breadth-First SearchYou are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 2121. Find if Path Exists in Graph - Easy - Breadth-First SearchThere is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1 (inclusive). The edges in the graph are represented as a... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 833. Bus Routes - Hard - Breadth-First SearchYou are given an array routes representing bus routes where routes[i] is a bus route that the ith bus repeats forever. For example, if routes[0] = [1,... Topics: Array, Hash Table, Breadth-First Search
- 770. Couples Holding Hands - Hard - Breadth-First SearchThere are n couples sitting in 2n seats arranged in a row and want to hold hands. The people and seats are represented by an integer array row where r... Topics: Greedy, Depth-First Search, Breadth-First Search, Union Find, Graph
- 547. Number of Provinces - Medium - Breadth-First SearchThere are n cities. Some of them are connected, while some are not. If city a is connected directly with city b, and city b is connected directly with... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 877. Shortest Path Visiting All Nodes - Hard - Breadth-First SearchYou have an undirected, connected graph of n nodes labeled from 0 to n - 1. You are given an array graph where graph[i] is a list of all the nodes con... Topics: Dynamic Programming, Bit Manipulation, Breadth-First Search, Graph, Bitmask
- 130. Surrounded Regions - Medium - Breadth-First SearchYou are given an m x n matrix board containing letters 'X' and 'O', capture regions that are surrounded: Connect: A cell is connected to adjacent cell... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 2558. Minimum Number of Operations to Sort a Binary Tree by Level - Medium - Breadth-First SearchYou are given the root of a binary tree with unique values. In one operation, you can choose any two nodes at the same level and swap their values. Re... Topics: Tree, Breadth-First Search, Binary Tree
- 655. Print Binary Tree - Medium - Breadth-First SearchGiven the root of a binary tree, construct a 0-indexed m x n string matrix res that represents a formatted layout of the tree. The formatted layout ma... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 1663. Detect Cycles in 2D Grid - Medium - Breadth-First SearchGiven a 2D array of characters grid of size m x n, you need to find if there exists any cycle consisting of the same value in grid. A cycle is a path ... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 1188. Brace Expansion II - Hard - Breadth-First SearchUnder the grammar given below, strings can represent a set of lowercase words. Let R(expr) denote the set of words the expression represents. The gram... Topics: String, Backtracking, Stack, Breadth-First Search
- 813. All Paths From Source to Target - Medium - Breadth-First SearchGiven a directed acyclic graph (DAG) of n nodes labeled from 0 to n - 1, find all possible paths from node 0 to node n - 1 and return them in any orde... Topics: Backtracking, Depth-First Search, Breadth-First Search, Graph
- 365. Water and Jug Problem - Medium - Breadth-First SearchYou are given two jugs with capacities x liters and y liters. You have an infinite water supply. Return whether the total amount of water in both jugs... Topics: Math, Depth-First Search, Breadth-First Search
- 2793. Count the Number of Complete Components - Medium - Breadth-First SearchYou are given an integer n. There is an undirected graph with n vertices, numbered from 0 to n - 1. You are given a 2D integer array edges where edges... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 2439. Longest Cycle in a Graph - Hard - Breadth-First SearchYou are given a directed graph of n nodes numbered from 0 to n - 1, where each node has at most one outgoing edge. The graph is represented with a giv... Topics: Depth-First Search, Breadth-First Search, Graph, Topological Sort
- 1492. Time Needed to Inform All Employees - Medium - Breadth-First SearchA company has n employees with a unique ID for each employee from 0 to n - 1. The head of the company is the one with headID. Each employee has one di... Topics: Tree, Depth-First Search, Breadth-First Search
- 2250. K Highest Ranked Items Within a Price Range - Medium - Breadth-First SearchYou are given a 0-indexed 2D integer array grid of size m x n that represents a map of the items in a shop. The integers in the grid represent the fol... Topics: Array, Breadth-First Search, Sorting, Heap (Priority Queue), Matrix
- 2206. Detonate the Maximum Bombs - Medium - Breadth-First SearchYou are given a list of bombs. The range of a bomb is defined as the area where its effect can be felt. This area is in the shape of a circle with the... Topics: Array, Math, Depth-First Search, Breadth-First Search, Graph, Geometry
- 1753. Path With Minimum Effort - Medium - Breadth-First SearchYou are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the heigh... Topics: Array, Binary Search, Depth-First Search, Breadth-First Search, Union Find, Heap (Priority Queue), Matrix
- 1117. As Far from Land as Possible - Medium - Breadth-First SearchGiven an n x n grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the ne... Topics: Array, Dynamic Programming, Breadth-First Search, Matrix
- 112. Path Sum - Easy - Breadth-First SearchGiven the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along the... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 310. Minimum Height Trees - Medium - Breadth-First SearchA tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles i... Topics: Depth-First Search, Breadth-First Search, Graph, Topological Sort
- 690. Employee Importance - Medium - Breadth-First SearchYou have a data structure of employee information, including the employee's unique ID, importance value, and direct subordinates' IDs. You are given a... Topics: Array, Hash Table, Tree, Depth-First Search, Breadth-First Search
- 1275. Validate Binary Tree Nodes - Medium - Breadth-First SearchYou have n binary tree nodes numbered from 0 to n - 1 where node i has two children leftChild[i] and rightChild[i], return true if and only if all the... Topics: Tree, Depth-First Search, Breadth-First Search, Union Find, Graph, Binary Tree
- 662. Maximum Width of Binary Tree - Medium - Breadth-First SearchGiven the root of a binary tree, return the maximum width of the given tree. The maximum width of a tree is the maximum width among all levels. The wi... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 998. Check Completeness of a Binary Tree - Medium - Breadth-First SearchGiven the root of a binary tree, determine if it is a complete binary tree. In a complete binary tree, every level, except possibly the last, is compl... Topics: Tree, Breadth-First Search, Binary Tree
- 2344. Escape the Spreading Fire - Hard - Breadth-First SearchYou are given a 0-indexed 2D integer array grid of size m x n which represents a field. Each cell has one of three values: 0 represents grass, 1 repre... Topics: Array, Binary Search, Breadth-First Search, Matrix
- 2662. Check Knight Tour Configuration - Medium - Breadth-First SearchThere is a knight on an n x n chessboard. In a valid configuration, the knight starts at the top-left cell of the board and visits every cell on the b... Topics: Array, Depth-First Search, Breadth-First Search, Matrix, Simulation
- 449. Serialize and Deserialize BST - Medium - Breadth-First SearchSerialization is converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted acr... Topics: String, Tree, Depth-First Search, Breadth-First Search, Design, Binary Search Tree, Binary Tree
- 1254. Deepest Leaves Sum - Medium - Breadth-First SearchGiven the root of a binary tree, return the sum of values of its deepest leaves.... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 463. Island Perimeter - Easy - Breadth-First SearchYou are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water. Grid cells are connected hor... Topics: Array, Depth-First Search, Breadth-First Search, Matrix
- 2461. Amount of Time for Binary Tree to Be Infected - Medium - Breadth-First SearchYou are given the root of a binary tree with unique values, and an integer start. At minute 0, an infection starts from the node with value start. Eac... Topics: Hash Table, Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 2671. Shortest Cycle in a Graph - Hard - Breadth-First SearchThere is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1. The edges in the graph are represented by a given 2D in... Topics: Breadth-First Search, Graph
- 685. Redundant Connection II - Hard - Breadth-First SearchIn this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this n... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 1493. Frog Position After T Seconds - Hard - Breadth-First SearchGiven an undirected tree consisting of n vertices numbered from 1 to n. A frog starts jumping from vertex 1. In one second, the frog jumps from its cu... Topics: Tree, Depth-First Search, Breadth-First Search, Graph
- 117. Populating Next Right Pointers in Each Node II - Medium - Breadth-First SearchGiven a binary tree struct Node { int val; Node *left; Node *right; Node *next; } Populate each next pointer to point to its next right node. If there... Topics: Linked List, Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 404. Sum of Left Leaves - Easy - Breadth-First SearchGiven the root of a binary tree, return the sum of all left leaves. A leaf is a node with no children. A left leaf is a leaf that is the left child of... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 514. Freedom Trail - Hard - Breadth-First SearchIn the video game Fallout 4, the quest "Road to Freedom" requires players to reach a metal dial called the "Freedom Trail Ring" and use the dial to sp... Topics: String, Dynamic Programming, Depth-First Search, Breadth-First Search
- 637. Average of Levels in Binary Tree - Easy - Breadth-First SearchGiven the root of a binary tree, return the average value of the nodes on each level in the form of an array. Answers within 10-5 of the actual answer... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 2409. Number of Increasing Paths in a Grid - Hard - Breadth-First SearchYou are given an m x n integer matrix grid, where you can move from a cell to any adjacent cell in all 4 directions. Return the number of strictly inc... Topics: Array, Dynamic Programming, Depth-First Search, Breadth-First Search, Graph, Topological Sort, Memoization, Matrix
- 2171. Second Minimum Time to Reach Destination - Hard - Breadth-First SearchA city is represented as a bi-directional connected graph with n vertices where each vertex is labeled from 1 to n (inclusive). The edges in the graph... Topics: Breadth-First Search, Graph, Shortest Path
- 2646. Kth Largest Sum in a Binary Tree - Medium - Breadth-First SearchYou are given the root of a binary tree and a positive integer k. The level sum in the tree is the sum of the values of the nodes that are on the same... Topics: Tree, Breadth-First Search, Sorting, Binary Tree
- 1757. Minimum Jumps to Reach Home - Medium - Breadth-First SearchA certain bug's home is on the x-axis at position x. Help them get there from position 0. The bug jumps according to the following rules: It can jump ... Topics: Array, Dynamic Programming, Breadth-First Search
- 871. Keys and Rooms - Medium - Breadth-First SearchThere are n rooms labeled from 0 to n - 1 and all the rooms are locked except for room 0. Your goal is to visit all the rooms. However, you cannot ent... Topics: Depth-First Search, Breadth-First Search, Graph
- 1876. Map of Highest Peak - Medium - Breadth-First SearchYou are given an integer matrix isWater of size m x n that represents a map of land and water cells. If isWater[i][j] == 0, cell (i, j) is a land cell... Topics: Array, Breadth-First Search, Matrix
- 488. Zuma Game - Hard - Breadth-First SearchYou are playing a variation of the game Zuma. In this variation of Zuma, there is a single row of colored balls on a board, where each ball can be col... Topics: String, Dynamic Programming, Stack, Breadth-First Search, Memoization
- 1116. Maximum Level Sum of a Binary Tree - Medium - Breadth-First SearchGiven the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level x such that the sum ... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 1005. Univalued Binary Tree - Easy - Breadth-First SearchA binary tree is uni-valued if every node in the tree has the same value. Given the root of a binary tree, return true if the given tree is uni-valued... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 2151. The Time When the Network Becomes Idle - Medium - Breadth-First SearchThere is a network of n servers, labeled from 0 to n - 1. You are given a 2D integer array edges, where edges[i] = [ui, vi] indicates there is a messa... Topics: Array, Breadth-First Search, Graph
- 1120. Flower Planting With No Adjacent - Medium - Breadth-First SearchYou have n gardens, labeled from 1 to n, and an array paths where paths[i] = [xi, yi] describes a bidirectional path between garden xi to garden yi. I... Topics: Depth-First Search, Breadth-First Search, Graph
- 2103. Find All Groups of Farmland - Medium - Breadth-First SearchYou are given a 0-indexed m x n binary matrix land where a 0 represents a hectare of forested land and a 1 represents a hectare of farmland. To keep t... Topics: Array, Depth-First Search, Breadth-First Search, Matrix
- 2493. Reverse Odd Levels of Binary Tree - Medium - Breadth-First SearchGiven the root of a perfect binary tree, reverse the node values at each odd level of the tree. For example, suppose the node values at level 3 are [2... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 100. Same Tree - Easy - Breadth-First SearchGiven the roots of two binary trees p and q, write a function to check if they are the same or not. Two binary trees are considered the same if they a... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 964. Minimize Malware Spread II - Hard - Breadth-First SearchYou are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i... Topics: Array, Hash Table, Depth-First Search, Breadth-First Search, Union Find, Graph
- 1442. Number of Operations to Make Network Connected - Medium - Breadth-First SearchThere are n computers numbered from 0 to n - 1 connected by ethernet cables connections forming a network where connections[i] = [ai, bi] represents a... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 1485. Minimum Cost to Make at Least One Valid Path in a Grid - Hard - Breadth-First SearchGiven an m x n grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i... Topics: Array, Breadth-First Search, Graph, Heap (Priority Queue), Matrix, Shortest Path
- 1424. Maximum Candies You Can Get from Boxes - Hard - Breadth-First SearchYou have n boxes labeled from 0 to n - 1. You are given four arrays: status, candies, keys, and containedBoxes where: status[i] is 1 if the ith box is... Topics: Array, Breadth-First Search, Graph
- 2588. Maximum Number of Points From Grid Queries - Hard - Breadth-First SearchYou are given an m x n integer matrix grid and an array queries of size k. Find an array answer of size k such that for each integer queries[i] you st... Topics: Array, Two Pointers, Breadth-First Search, Union Find, Sorting, Heap (Priority Queue), Matrix
- 922. Possible Bipartition - Medium - Breadth-First SearchWe want to split a group of n people (labeled from 1 to n) into two groups of any size. Each person may dislike some other people, and they should not... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 820. Find Eventual Safe States - Medium - Breadth-First SearchThere is a directed graph of n nodes with each node labeled from 0 to n - 1. The graph is represented by a 0-indexed 2D integer array graph where grap... Topics: Depth-First Search, Breadth-First Search, Graph, Topological Sort
- 2582. Minimum Score of a Path Between Two Cities - Medium - Breadth-First SearchYou are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads where roads[i] = [ai, bi, distancei... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 869. Similar String Groups - Hard - Breadth-First SearchTwo strings, X and Y, are considered similar if either they are identical or we can make them equivalent by swapping at most two letters (in distinct ... Topics: Array, Hash Table, String, Depth-First Search, Breadth-First Search, Union Find
- 2403. Count Unreachable Pairs of Nodes in an Undirected Graph - Medium - Breadth-First SearchYou are given an integer n. There is an undirected graph with n nodes, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i]... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 2914. Find the Safest Path in a Grid - Medium - Breadth-First SearchYou are given a 0-indexed 2D matrix grid of size n x n, where (r, c) represents: A cell containing a thief if grid[r][c] = 1 An empty cell if grid[r][... Topics: Array, Binary Search, Breadth-First Search, Union Find, Heap (Priority Queue), Matrix
- 1104. Coloring A Border - Medium - Breadth-First SearchYou are given an m x n integer matrix grid, and three integers row, col, and color. Each value in the grid represents the color of the grid square at ... Topics: Array, Depth-First Search, Breadth-First Search, Matrix
- 3720. Minimize the Maximum Edge Weight of Graph - Medium - Breadth-First SearchYou are given two integers, n and threshold, as well as a directed weighted graph of n nodes numbered from 0 to n - 1. The graph is represented by a 2... Topics: Binary Search, Depth-First Search, Breadth-First Search, Graph, Shortest Path
- 960. Minimize Malware Spread - Hard - Breadth-First SearchYou are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i... Topics: Array, Hash Table, Depth-First Search, Breadth-First Search, Union Find, Graph
- 3105. Minimum Edge Reversals So Every Node Is Reachable - Hard - Breadth-First SearchThere is a simple directed graph with n nodes labeled from 0 to n - 1. The graph would form a tree if its edges were bi-directional. You are given an ... Topics: Dynamic Programming, Depth-First Search, Breadth-First Search, Graph
- 3809. Properties Graph - Medium - Breadth-First SearchYou are given a 2D integer array properties having dimensions n x m and an integer k. Define a function intersect(a, b) that returns the number of dis... Topics: Array, Hash Table, Depth-First Search, Breadth-First Search, Union Find, Graph
- 757. Pyramid Transition Matrix - Medium - Breadth-First SearchYou are stacking blocks to form a pyramid. Each block has a color, which is represented by a single letter. Each row of blocks contains one less block... Topics: Bit Manipulation, Depth-First Search, Breadth-First Search
- 2677. Cousins in Binary Tree II - Medium - Breadth-First SearchGiven the root of a binary tree, replace the value of each node in the tree with the sum of all its cousins' values. Two nodes of a binary tree are co... Topics: Hash Table, Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 1731. Even Odd Tree - Medium - Breadth-First SearchA binary tree is named Even-Odd if it meets the following conditions: The root of the binary tree is at level index 0, its children are at level index... Topics: Tree, Breadth-First Search, Binary Tree
- 3560. Maximum Number of Moves to Kill All Pawns - Hard - Breadth-First SearchThere is a 50 x 50 chessboard with one knight and some pawns on it. You are given two integers kx and ky where (kx, ky) denotes the position of the kn... Topics: Array, Math, Bit Manipulation, Breadth-First Search, Game Theory, Bitmask
- 672. Bulb Switcher II - Medium - Breadth-First SearchThere is a room with n bulbs labeled from 1 to n that all are turned on initially, and four buttons on the wall. Each of the four buttons has a differ... Topics: Math, Bit Manipulation, Depth-First Search, Breadth-First Search
- 3271. Count the Number of Houses at a Certain Distance I - Medium - Breadth-First SearchYou are given three positive integers n, x, and y. In a city, there exist houses numbered 1 to n connected by n streets. There is a street connecting ... Topics: Breadth-First Search, Graph, Prefix Sum
- 1576. Reorder Routes to Make All Paths Lead to the City Zero - Medium - Breadth-First SearchThere are n cities numbered from 0 to n - 1 and n - 1 roads such that there is only one way to travel between two different cities (this network form ... Topics: Depth-First Search, Breadth-First Search, Graph
- 3933. Minimum Jumps to Reach End via Prime Teleportation - Medium - Breadth-First SearchYou are given an integer array nums of length n. You start at index 0, and your goal is to reach index n - 1. From any index i, you may perform one of... Topics: Array, Hash Table, Math, Breadth-First Search, Number Theory
- 1431. All Ancestors of a Node in a Directed Acyclic Graph - Medium - Breadth-First SearchYou are given a positive integer n representing the number of nodes of a Directed Acyclic Graph (DAG). The nodes are numbered from 0 to n - 1 (inclusi... Topics: Depth-First Search, Breadth-First Search, Graph, Topological Sort
- 1554. Minimum Time to Collect All Apples in a Tree - Medium - Breadth-First SearchGiven an undirected tree consisting of n vertices numbered from 0 to n-1, which has some apples in their vertices. You spend 1 second to walk over one... Topics: Hash Table, Tree, Depth-First Search, Breadth-First Search
- 955. Complete Binary Tree Inserter - Medium - Breadth-First SearchA complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possibl... Topics: Tree, Breadth-First Search, Design, Binary Tree
- 3645. Maximize the Number of Target Nodes After Connecting Trees II - Hard - Breadth-First SearchThere exist two undirected trees with n and m nodes, labeled from [0, n - 1] and [0, m - 1], respectively. You are given two 2D integer arrays edges1 ... Topics: Tree, Depth-First Search, Breadth-First Search
- 896. Smallest Subtree with all the Deepest Nodes - Medium - Breadth-First SearchGiven the root of a binary tree, the depth of each node is the shortest distance to the root. Return the smallest subtree such that it contains all th... Topics: Hash Table, Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 1218. Lowest Common Ancestor of Deepest Leaves - Medium - Breadth-First SearchGiven the root of a binary tree, return the lowest common ancestor of its deepest leaves. Recall that: The node of a binary tree is a leaf if and only... Topics: Hash Table, Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 1691. Minimum Number of Days to Disconnect Island - Hard - Breadth-First SearchYou are given an m x n binary grid grid where 1 represents land and 0 represents water. An island is a maximal 4-directionally (horizontal or vertical... Topics: Array, Depth-First Search, Breadth-First Search, Matrix, Strongly Connected Component
- 515. Find Largest Value in Each Tree Row - Medium - Breadth-First SearchGiven the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed).... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 3837. Grid Teleportation Traversal - Medium - Breadth-First SearchYou are given a 2D character grid matrix of size m x n, represented as an array of strings, where matrix[i][j] represents the cell at the intersection... Topics: Array, Hash Table, Breadth-First Search, Matrix
- 3239. Minimum Number of Operations to Make X and Y Equal - Medium - Breadth-First SearchYou are given two positive integers x and y. In one operation, you can do one of the four following operations: Divide x by 11 if x is a multiple of 1... Topics: Dynamic Programming, Breadth-First Search, Memoization
- 3870. Minimum Moves to Clean the Classroom - Medium - Breadth-First SearchYou are given an m x n grid classroom where a student volunteer is tasked with cleaning up litter scattered around the room. Each cell in the grid is ... Topics: Array, Hash Table, Bit Manipulation, Breadth-First Search, Matrix
- 1243. Sum of Nodes with Even-Valued Grandparent - Medium - Breadth-First SearchGiven the root of a binary tree, return the sum of values of nodes with an even-valued grandparent. If there are no nodes with an even-valued grandpar... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 1296. Kth Ancestor of a Tree Node - Hard - Breadth-First SearchYou are given a tree with n nodes numbered from 0 to n - 1 in the form of a parent array parent where parent[i] is the parent of ith node. The root of... Topics: Binary Search, Dynamic Programming, Tree, Depth-First Search, Breadth-First Search, Design
- 750. Contain Virus - Hard - Breadth-First SearchA virus is spreading rapidly, and your task is to quarantine the infected area by installing walls. The world is modeled as an m x n binary grid isInf... Topics: Array, Depth-First Search, Breadth-First Search, Matrix, Simulation
- 3558. Find a Safe Walk Through a Grid - Medium - Breadth-First SearchYou are given an m x n binary matrix grid and an integer health. You start on the upper-left corner (0, 0) and would like to get to the lower-right co... Topics: Array, Breadth-First Search, Graph, Heap (Priority Queue), Matrix, Shortest Path
- 675. Cut Off Trees for Golf Event - Hard - Breadth-First SearchYou are asked to cut off all the trees in a forest for a golf event. The forest is represented as an m x n matrix. In this matrix: 0 means the cell ca... Topics: Array, Breadth-First Search, Heap (Priority Queue), Matrix
- 799. Minimum Distance Between BST Nodes - Easy - Breadth-First SearchGiven the root of a Binary Search Tree (BST), return the minimum difference between the values of any two different nodes in the tree.... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Search Tree, Binary Tree
- 3092. Minimum Moves to Spread Stones Over Grid - Medium - Breadth-First SearchYou are given a 0-indexed 2D integer matrix grid of size 3 * 3, representing the number of stones in each cell. The grid contains exactly 9 stones, an... Topics: Array, Dynamic Programming, Breadth-First Search, Matrix
- 3439. Find Minimum Diameter After Merging Two Trees - Hard - Breadth-First SearchThere exist two undirected trees with n and m nodes, numbered from 0 to n - 1 and from 0 to m - 1, respectively. You are given two 2D integer arrays e... Topics: Tree, Depth-First Search, Breadth-First Search, Graph
- 2564. Most Profitable Path in a Tree - Medium - Breadth-First SearchThere is an undirected tree with n nodes labeled from 0 to n - 1, rooted at node 0. You are given a 2D integer array edges of length n - 1 where edges... Topics: Array, Tree, Depth-First Search, Breadth-First Search, Graph
- 2568. Minimum Fuel Cost to Report to the Capital - Medium - Breadth-First SearchThere is a tree (i.e., a connected, undirected graph with no cycles) structure country network consisting of n cities numbered from 0 to n - 1 and exa... Topics: Tree, Depth-First Search, Breadth-First Search, Graph
- 1073. Number of Enclaves - Medium - Breadth-First SearchYou are given an m x n binary matrix grid, where 0 represents a sea cell and 1 represents a land cell. A move consists of walking from one land cell t... Topics: Array, Depth-First Search, Breadth-First Search, Union Find, Matrix
- 1498. Find a Corresponding Node of a Binary Tree in a Clone of That Tree - Easy - Breadth-First SearchGiven two binary trees original and cloned and given a reference to a node target in the original tree. The cloned tree is a copy of the original tree... Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree
- 2375. Minimum Obstacle Removal to Reach Corner - Hard - Breadth-First SearchYou are given a 0-indexed 2D integer array grid of size m x n. Each cell has one of two values: 0 represents an empty cell, 1 represents an obstacle t... Topics: Array, Breadth-First Search, Graph, Heap (Priority Queue), Matrix, Shortest Path
- 1389. Minimum Moves to Move a Box to Their Target Location - Hard - Breadth-First SearchA storekeeper is a game in which the player pushes boxes around in a warehouse trying to get them to target locations. The game is represented by an m... Topics: Array, Breadth-First Search, Heap (Priority Queue), Matrix
- 774. Maximum Depth of N-ary Tree - Easy - Breadth-First SearchGiven a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest le... Topics: Tree, Depth-First Search, Breadth-First Search
- 895. Shortest Path to Get All Keys - Hard - Breadth-First SearchYou are given an m x n grid grid where: '.' is an empty cell. '#' is a wall. '@' is the starting point. Lowercase letters represent keys. Uppercase le... Topics: Array, Bit Manipulation, Breadth-First Search, Matrix
- 3386. Find Edges in Shortest Paths - Hard - Breadth-First SearchYou are given an undirected weighted graph of n nodes numbered from 0 to n - 1. The graph consists of m edges represented by a 2D array edges, where e... Topics: Depth-First Search, Breadth-First Search, Graph, Heap (Priority Queue), Shortest Path
- 2583. Divide Nodes Into the Maximum Number of Groups - Hard - Breadth-First SearchYou are given a positive integer n representing the number of nodes in an undirected graph. The nodes are labeled from 1 to n. You are also given a 2D... Topics: Depth-First Search, Breadth-First Search, Union Find, Graph
- 1409. Minimum Number of Flips to Convert Binary Matrix to Zero Matrix - Hard - Breadth-First SearchGiven a m x n binary matrix mat. In one step, you can choose one cell and flip it and all the four neighbors of it if they exist (Flip is changing 1 t... Topics: Array, Hash Table, Bit Manipulation, Breadth-First Search, Matrix
- 1229. Shortest Path with Alternating Colors - Medium - Breadth-First SearchYou are given an integer n, the number of nodes in a directed graph where the nodes are labeled from 0 to n - 1. Each edge is red or blue in this grap... Topics: Breadth-First Search, Graph
- 2104. Operations on Tree - Medium - Breadth-First SearchYou are given a tree with n nodes numbered from 0 to n - 1 in the form of a parent array parent where parent[i] is the parent of the ith node. The roo... Topics: Array, Hash Table, Tree, Depth-First Search, Breadth-First Search, Design
- 2545. Height of Binary Tree After Subtree Removal Queries - Hard - Breadth-First SearchYou are given the root of a binary tree with n nodes. Each node is assigned a unique value from 1 to n. You are also given an array queries of size m.... Topics: Array, Tree, Depth-First Search, Breadth-First Search, Binary Tree
Related LeetCode Topics
- Array LeetCode Problems
- Backtracking LeetCode Problems
- Biconnected Component LeetCode Problems
- Binary Indexed Tree LeetCode Problems
- Binary Search LeetCode Problems
- Binary Search Tree LeetCode Problems
- Binary Tree LeetCode Problems
- Bit Manipulation LeetCode Problems
- Bitmask LeetCode Problems
- Brainteaser LeetCode Problems
- Bucket Sort LeetCode Problems
- Combinatorics LeetCode Problems
- Concurrency LeetCode Problems
- Counting LeetCode Problems
- Counting Sort LeetCode Problems
- Data Stream LeetCode Problems
- Database LeetCode Problems
- Depth-First Search LeetCode Problems
- Design LeetCode Problems
- Divide and Conquer LeetCode Problems