Depth-First Search Problems
Master depth-first search problems with AI-powered solutions. Get instant coding assistance during your technical interviews for all 208 problems in this category.
Total Problems: 208
Easy: 36
Medium: 121
Hard: 51
Showing 50 of 208 problems
Problems
Scroll within this area to browse all problems
#
Title
Difficulty
Depth-First Search LeetCode Problems List
- 207. Course Schedule - Medium - Depth-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
- 144. Binary Tree Preorder Traversal - Easy - Depth-First SearchGiven the root of a binary tree, return the preorder traversal of its nodes' values.... Topics: Stack, Tree, Depth-First Search, Binary Tree
- 94. Binary Tree Inorder Traversal - Easy - Depth-First SearchGiven the root of a binary tree, return the inorder traversal of its nodes' values.... Topics: Stack, Tree, Depth-First Search, Binary Tree
- 226. Invert Binary Tree - Easy - Depth-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
- 200. Number of Islands - Medium - Depth-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
- 236. Lowest Common Ancestor of a Binary Tree - Medium - Depth-First SearchGiven a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowes... Topics: Tree, Depth-First Search, Binary Tree
- 79. Word Search - Medium - Depth-First SearchGiven an m x n grid of characters board and a string word, return true if word exists in the grid. The word can be constructed from letters of sequent... Topics: Array, String, Backtracking, Depth-First Search, Matrix
- 145. Binary Tree Postorder Traversal - Easy - Depth-First SearchGiven the root of a binary tree, return the postorder traversal of its nodes' values.... Topics: Stack, Tree, Depth-First Search, Binary Tree
- 721. Accounts Merge - Medium - Depth-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
- 98. Validate Binary Search Tree - Medium - Depth-First SearchGiven the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows: The left subtree of a node co... Topics: Tree, Depth-First Search, Binary Search Tree, Binary Tree
- 803. Cheapest Flights Within K Stops - Medium - Depth-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
- 110. Balanced Binary Tree - Easy - Depth-First SearchGiven a binary tree, determine if it is height-balanced.... Topics: Tree, Depth-First Search, Binary Tree
- 543. Diameter of Binary Tree - Easy - Depth-First SearchGiven the root of a binary tree, return the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path betwee... Topics: Tree, Depth-First Search, Binary Tree
- 733. Flood Fill - Easy - Depth-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 - Depth-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 - Depth-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 - Depth-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
- 124. Binary Tree Maximum Path Sum - Hard - Depth-First SearchA path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear i... Topics: Dynamic Programming, Tree, Depth-First Search, Binary Tree
- 1029. Vertical Order Traversal of a Binary Tree - Hard - Depth-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 - Depth-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
- 235. Lowest Common Ancestor of a Binary Search Tree - Medium - Depth-First SearchGiven a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST. According to the definition of LCA on Wiki... Topics: Tree, Depth-First Search, Binary Search Tree, Binary Tree
- 529. Minesweeper - Medium - Depth-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
- 114. Flatten Binary Tree to Linked List - Medium - Depth-First SearchGiven the root of a binary tree, flatten the tree into a "linked list": The "linked list" should use the same TreeNode class where the right child poi... Topics: Linked List, Stack, Tree, Depth-First Search, Binary Tree
- 133. Clone Graph - Medium - Depth-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 - Depth-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 - Depth-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
- 572. Subtree of Another Tree - Easy - Depth-First SearchGiven the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and... Topics: Tree, Depth-First Search, String Matching, Binary Tree, Hash Function
- 230. Kth Smallest Element in a BST - Medium - Depth-First SearchGiven the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree.... Topics: Tree, Depth-First Search, Binary Search Tree, Binary Tree
- 329. Longest Increasing Path in a Matrix - Hard - Depth-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
- 129. Sum Root to Leaf Numbers - Medium - Depth-First SearchYou are given the root of a binary tree containing digits from 0 to 9 only. Each root-to-leaf path in the tree represents a number. For example, the r... Topics: Tree, Depth-First Search, Binary Tree
- 101. Symmetric Tree - Easy - Depth-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 - Depth-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
- 341. Flatten Nested List Iterator - Medium - Depth-First SearchYou are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. Im... Topics: Stack, Tree, Depth-First Search, Design, Queue, Iterator
- 617. Merge Two Binary Trees - Easy - Depth-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 - Depth-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 - Depth-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 - Depth-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 - Depth-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
- 1285. Balance a Binary Search Tree - Medium - Depth-First SearchGiven the root of a binary search tree, return a balanced binary search tree with the same node values. If there is more than one answer, return any o... Topics: Divide and Conquer, Greedy, Tree, Depth-First Search, Binary Search Tree, Binary Tree
- 399. Evaluate Division - Medium - Depth-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 - Depth-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 - Depth-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 - Depth-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
- 211. Design Add and Search Words Data Structure - Medium - Depth-First SearchDesign a data structure that supports adding new words and finding if a string matches any previously added string. Implement the WordDictionary class... Topics: String, Depth-First Search, Design, Trie
- 1558. Course Schedule IV - Medium - Depth-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 - Depth-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
- 99. Recover Binary Search Tree - Medium - Depth-First SearchYou are given the root of a binary search tree (BST), where the values of exactly two nodes of the tree were swapped by mistake. Recover the tree with... Topics: Tree, Depth-First Search, Binary Search Tree, Binary Tree
- 744. Network Delay Time - Medium - Depth-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
- 1106. Escape a Large Maze - Hard - Depth-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
- 975. Range Sum of BST - Easy - Depth-First SearchGiven the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [... Topics: Tree, Depth-First Search, Binary Search Tree, Binary Tree
- 530. Minimum Absolute Difference in BST - Easy - Depth-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 - Depth-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 - Depth-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 - Depth-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 - Depth-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
- 1380. Number of Closed Islands - Medium - Depth-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 - Depth-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
- 3823. Count Islands With Total Value Divisible by K - Medium - Depth-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 - Depth-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
- 695. Max Area of Island - Medium - Depth-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 - Depth-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
- 770. Couples Holding Hands - Hard - Depth-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 - Depth-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
- 130. Surrounded Regions - Medium - Depth-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
- 1021. Distribute Coins in Binary Tree - Medium - Depth-First SearchYou are given the root of a binary tree with n nodes where each node in the tree has node.val coins. There are n coins in total throughout the whole t... Topics: Tree, Depth-First Search, Binary Tree
- 419. Battleships in a Board - Medium - Depth-First SearchGiven an m x n matrix board where each cell is a battleship 'X' or empty '.', return the number of the battleships on board. Battleships can only be p... Topics: Array, Depth-First Search, Matrix
- 766. Flatten a Multilevel Doubly Linked List - Medium - Depth-First SearchYou are given a doubly linked list, which contains nodes that have a next pointer, a previous pointer, and an additional child pointer. This child poi... Topics: Linked List, Depth-First Search, Doubly-Linked List
- 655. Print Binary Tree - Medium - Depth-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 - Depth-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
- 813. All Paths From Source to Target - Medium - Depth-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 - Depth-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
- 2567. Closest Nodes Queries in a Binary Search Tree - Medium - Depth-First SearchYou are given the root of a binary search tree and an array queries of size n consisting of positive integers. Find a 2D array answer of size n where ... Topics: Array, Binary Search, Tree, Depth-First Search, Binary Search Tree, Binary Tree
- 1079. Sum of Root To Leaf Binary Numbers - Easy - Depth-First SearchYou are given the root of a binary tree where each node has a value 0 or 1. Each root-to-leaf path represents a binary number starting with the most s... Topics: Tree, Depth-First Search, Binary Tree
- 337. House Robber III - Medium - Depth-First SearchThe thief has found himself a new place for his thievery again. There is only one entrance to this area, called root. Besides the root, each house has... Topics: Dynamic Programming, Tree, Depth-First Search, Binary Tree
- 2364. Longest Path With Different Adjacent Characters - Hard - Depth-First SearchYou are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node 0 consisting of n nodes numbered from 0 to n - 1. The tree... Topics: Array, String, Tree, Depth-First Search, Graph, Topological Sort
- 2793. Count the Number of Complete Components - Medium - Depth-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 - Depth-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
- 1300. Critical Connections in a Network - Hard - Depth-First SearchThere are n servers numbered from 0 to n - 1 connected by undirected server-to-server connections forming a network where connections[i] = [ai, bi] re... Topics: Depth-First Search, Graph, Biconnected Component
- 1492. Time Needed to Inform All Employees - Medium - Depth-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
- 332. Reconstruct Itinerary - Hard - Depth-First SearchYou are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reconstruct th... Topics: Depth-First Search, Graph, Eulerian Circuit
- 2206. Detonate the Maximum Bombs - Medium - Depth-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 - Depth-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
- 112. Path Sum - Easy - Depth-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 - Depth-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 - Depth-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
- 988. Flip Equivalent Binary Trees - Medium - Depth-First SearchFor a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees. A binary tree X is flip e... Topics: Tree, Depth-First Search, Binary Tree
- 1275. Validate Binary Tree Nodes - Medium - Depth-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 - Depth-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
- 2627. Difference Between Maximum and Minimum Price Sum - Hard - Depth-First SearchThere exists an undirected and initially unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and a 2D integer array edges ... Topics: Array, Dynamic Programming, Tree, Depth-First Search
- 2662. Check Knight Tour Configuration - Medium - Depth-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 - Depth-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 - Depth-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 - Depth-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 - Depth-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
- 1114. Binary Search Tree to Greater Sum Tree - Medium - Depth-First SearchGiven the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus... Topics: Tree, Depth-First Search, Binary Search Tree, Binary Tree
- 685. Redundant Connection II - Hard - Depth-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
- 257. Binary Tree Paths - Easy - Depth-First SearchGiven the root of a binary tree, return all root-to-leaf paths in any order. A leaf is a node with no children.... Topics: String, Backtracking, Tree, Depth-First Search, Binary Tree
- 1493. Frog Position After T Seconds - Hard - Depth-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 - Depth-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 - Depth-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 - Depth-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 - Depth-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 - Depth-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
- 386. Lexicographical Numbers - Medium - Depth-First SearchGiven an integer n, return all the numbers in the range [1, n] sorted in lexicographical order. You must write an algorithm that runs in O(n) time and... Topics: Depth-First Search, Trie
- 776. N-ary Tree Postorder Traversal - Easy - Depth-First SearchGiven the root of an n-ary tree, return the postorder traversal of its nodes' values. Nary-Tree input serialization is represented in their level orde... Topics: Stack, Tree, Depth-First Search
- 775. N-ary Tree Preorder Traversal - Easy - Depth-First SearchGiven the root of an n-ary tree, return the preorder traversal of its nodes' values. Nary-Tree input serialization is represented in their level order... Topics: Stack, Tree, Depth-First Search
- 113. Path Sum II - Medium - Depth-First SearchGiven the root of a binary tree and an integer targetSum, return all root-to-leaf paths where the sum of the node values in the path equals targetSum.... Topics: Backtracking, Tree, Depth-First Search, Binary Tree
- 1092. Maximum Difference Between Node and Ancestor - Medium - Depth-First SearchGiven the root of a binary tree, find the maximum value v for which there exist different nodes a and b where v = |a.val - b.val| and a is an ancestor... Topics: Tree, Depth-First Search, Binary Tree
- 871. Keys and Rooms - Medium - Depth-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
- 676. Implement Magic Dictionary - Medium - Depth-First SearchDesign a data structure that is initialized with a list of different words. Provided a string, you should determine if you can change exactly one char... Topics: Hash Table, String, Depth-First Search, Design, Trie
- 2060. Merge BSTs to Create Single BST - Hard - Depth-First SearchYou are given n BST (binary search tree) root nodes for n separate BSTs stored in an array trees (0-indexed). Each BST in trees has at most 3 nodes, a... Topics: Hash Table, Binary Search, Tree, Depth-First Search, Binary Tree
- 671. Second Minimum Node In a Binary Tree - Easy - Depth-First SearchGiven a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. ... Topics: Tree, Depth-First Search, Binary Tree
- 1116. Maximum Level Sum of a Binary Tree - Medium - Depth-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 - Depth-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
- 1866. Restore the Array From Adjacent Pairs - Medium - Depth-First SearchThere is an integer array nums that consists of n unique elements, but you have forgotten it. However, you do remember every pair of adjacent elements... Topics: Array, Hash Table, Depth-First Search
- 1120. Flower Planting With No Adjacent - Medium - Depth-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 - Depth-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
- 437. Path Sum III - Medium - Depth-First SearchGiven the root of a binary tree and an integer targetSum, return the number of paths where the sum of the values along the path equals targetSum. The ... Topics: Tree, Depth-First Search, Binary Tree
- 2493. Reverse Odd Levels of Binary Tree - Medium - Depth-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
- 3854. Maximum Profit from Trading Stocks with Discounts - Hard - Depth-First SearchYou are given an integer n, representing the number of employees in a company. Each employee is assigned a unique ID from 1 to n, and employee 1 is th... Topics: Array, Dynamic Programming, Tree, Depth-First Search
- 100. Same Tree - Easy - Depth-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 - Depth-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
- 538. Convert BST to Greater Tree - Medium - Depth-First SearchGiven the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus... Topics: Tree, Depth-First Search, Binary Search Tree, Binary Tree
- 1350. Remove Sub-Folders from the Filesystem - Medium - Depth-First SearchGiven a list of folders folder, return the folders after removing all sub-folders in those folders. You may return the answer in any order. If a folde... Topics: Array, String, Depth-First Search, Trie
- 1442. Number of Operations to Make Network Connected - Medium - Depth-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
- 3486. Count the Number of Good Nodes - Medium - Depth-First SearchThere is an undirected tree with n nodes labeled from 0 to n - 1, and rooted at node 0. You are given a 2D integer array edges of length n - 1, where ... Topics: Tree, Depth-First Search
- 904. Leaf-Similar Trees - Easy - Depth-First SearchConsider all the leaves of a binary tree, from left to right order, the values of those leaves form a leaf value sequence. For example, in the given t... Topics: Tree, Depth-First Search, Binary Tree
- 1030. Smallest String Starting From Leaf - Medium - Depth-First SearchYou are given the root of a binary tree where each node has a value in the range [0, 25] representing the letters 'a' to 'z'. Return the lexicographic... Topics: String, Backtracking, Tree, Depth-First Search, Binary Tree
- 3909. Minimum Increments to Equalize Leaf Paths - Medium - Depth-First SearchYou are given an integer n and an undirected tree rooted at node 0 with n nodes numbered from 0 to n - 1. This is represented by a 2D array edges of l... Topics: Array, Dynamic Programming, Tree, Depth-First Search
- 1484. Linked List in Binary Tree - Medium - Depth-First SearchGiven a binary tree root and a linked list with head as the first node. Return True if all the elements in the linked list starting from the head corr... Topics: Linked List, Tree, Depth-First Search, Binary Tree
- 1207. Delete Nodes And Return Forest - Medium - Depth-First SearchGiven the root of a binary tree, each node in the tree has a distinct value. After deleting all nodes with a value in to_delete, we are left with a fo... Topics: Array, Hash Table, Tree, Depth-First Search, Binary Tree
- 3649. Minimum Time to Break Locks I - Medium - Depth-First SearchBob is stuck in a dungeon and must break n locks, each requiring some amount of energy to break. The required energy for each lock is stored in an arr... Topics: Array, Dynamic Programming, Backtracking, Bit Manipulation, Depth-First Search, Bitmask
- 2531. Create Components With Same Value - Hard - Depth-First SearchThere is an undirected tree with n nodes labeled from 0 to n - 1. You are given a 0-indexed integer array nums of length n where nums[i] represents th... Topics: Array, Math, Tree, Depth-First Search, Enumeration
- 984. Most Stones Removed with Same Row or Column - Medium - Depth-First SearchOn a 2D plane, we place n stones at some integer coordinate points. Each coordinate point may have at most one stone. A stone can be removed if it sha... Topics: Hash Table, Depth-First Search, Union Find, Graph
- 922. Possible Bipartition - Medium - Depth-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 - Depth-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
- 2217. Step-By-Step Directions From a Binary Tree Node to Another - Medium - Depth-First SearchYou are given the root of a binary tree with n nodes. Each node is uniquely assigned a value from 1 to n. You are also given an integer startValue rep... Topics: String, Tree, Depth-First Search, Binary Tree
- 1427. All Elements in Two Binary Search Trees - Medium - Depth-First SearchGiven two binary search trees root1 and root2, return a list containing all the integers from both trees sorted in ascending order.... Topics: Tree, Depth-First Search, Binary Search Tree, Sorting, Binary Tree
- 2582. Minimum Score of a Path Between Two Cities - Medium - Depth-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
- 1008. Binary Tree Cameras - Hard - Depth-First SearchYou are given the root of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its imme... Topics: Dynamic Programming, Tree, Depth-First Search, Binary Tree
- 869. Similar String Groups - Hard - Depth-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 - Depth-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
- 3906. Kth Smallest Path XOR Sum - Hard - Depth-First SearchYou are given an undirected tree rooted at node 0 with n nodes numbered from 0 to n - 1. Each node i has an integer value vals[i], and its parent is g... Topics: Array, Tree, Depth-First Search, Ordered Set
- 754. Cracking the Safe - Hard - Depth-First SearchThere is a safe protected by a password. The password is a sequence of n digits where each digit can be in the range [0, k - 1]. The safe has a peculi... Topics: Depth-First Search, Graph, Eulerian Circuit
- 1104. Coloring A Border - Medium - Depth-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 - Depth-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
- 669. Trim a Binary Search Tree - Medium - Depth-First SearchGiven the root of a binary search tree and the lowest and highest boundaries as low and high, trim the tree so that all its elements lies in [low, hig... Topics: Tree, Depth-First Search, Binary Search Tree, Binary Tree
- 2416. Evaluate Boolean Binary Tree - Easy - Depth-First SearchYou are given the root of a full binary tree with the following properties: Leaf nodes have either the value 0 or 1, where 0 represents False and 1 re... Topics: Tree, Depth-First Search, Binary Tree
- 960. Minimize Malware Spread - Hard - Depth-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
- 687. Longest Univalue Path - Medium - Depth-First SearchGiven the root of a binary tree, return the length of the longest path, where each node in the path has the same value. This path may or may not pass ... Topics: Tree, Depth-First Search, Binary Tree
- 863. Sum of Distances in Tree - Hard - Depth-First SearchThere is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are given the integer n and the array edges where edge... Topics: Dynamic Programming, Tree, Depth-First Search, Graph
- 3105. Minimum Edge Reversals So Every Node Is Reachable - Hard - Depth-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
- 3900. Find Weighted Median Node in Tree - Hard - Depth-First SearchYou are given an integer n and an undirected, weighted tree rooted at node 0 with n nodes numbered from 0 to n - 1. This is represented by a 2D array ... Topics: Array, Binary Search, Dynamic Programming, Tree, Depth-First Search
- 3809. Properties Graph - Medium - Depth-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 - Depth-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 - Depth-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
- 388. Longest Absolute File Path - Medium - Depth-First SearchSuppose we have a file system that stores both files and directories. An example of one system is represented in the following picture: Here, we have ... Topics: String, Stack, Depth-First Search
- 672. Bulb Switcher II - Medium - Depth-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
- 2131. Smallest Missing Genetic Value in Each Subtree - Hard - Depth-First SearchThere is a family tree rooted at 0 consisting of n nodes numbered 0 to n - 1. You are given a 0-indexed integer array parents, where parents[i] is the... Topics: Dynamic Programming, Tree, Depth-First Search, Union Find
- 1576. Reorder Routes to Make All Paths Lead to the City Zero - Medium - Depth-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
- 501. Find Mode in Binary Search Tree - Easy - Depth-First SearchGiven the root of a binary search tree (BST) with duplicates, return all the mode(s) (i.e., the most frequently occurred element) in it. If the tree h... Topics: Tree, Depth-First Search, Binary Search Tree, Binary Tree
- 1431. All Ancestors of a Node in a Directed Acyclic Graph - Medium - Depth-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 - Depth-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
- 2246. Maximum Employees to Be Invited to a Meeting - Hard - Depth-First SearchA company is organizing a meeting and has a list of n employees, waiting to be invited. They have arranged for a large circular table, capable of seat... Topics: Depth-First Search, Graph, Topological Sort
- 3875. Maximum Good Subtree Score - Hard - Depth-First SearchYou are given an undirected tree rooted at node 0 with n nodes numbered from 0 to n - 1. Each node i has an integer value vals[i], and its parent is g... Topics: Array, Dynamic Programming, Bit Manipulation, Tree, Depth-First Search, Bitmask
- 3645. Maximize the Number of Target Nodes After Connecting Trees II - Hard - Depth-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
- 2347. Count Nodes Equal to Average of Subtree - Medium - Depth-First SearchGiven the root of a binary tree, return the number of nodes where the value of the node is equal to the average of the values in its subtree. Note: Th... Topics: Tree, Depth-First Search, Binary Tree
- 832. Binary Tree Pruning - Medium - Depth-First SearchGiven the root of a binary tree, return the same tree where every subtree (of the given tree) not containing a 1 has been removed. A subtree of a node... Topics: Tree, Depth-First Search, Binary Tree
- 896. Smallest Subtree with all the Deepest Nodes - Medium - Depth-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 - Depth-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
- 3842. Number of Ways to Assign Edge Weights II - Hard - Depth-First SearchThere is an undirected tree with n nodes labeled from 1 to n, rooted at node 1. The tree is represented by a 2D integer array edges of length n - 1, w... Topics: Array, Math, Dynamic Programming, Tree, Depth-First Search
- 563. Binary Tree Tilt - Easy - Depth-First SearchGiven the root of a binary tree, return the sum of every tree node's tilt. The tilt of a tree node is the absolute difference between the sum of all l... Topics: Tree, Depth-First Search, Binary Tree
- 1691. Minimum Number of Days to Disconnect Island - Hard - Depth-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 - Depth-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
- 508. Most Frequent Subtree Sum - Medium - Depth-First SearchGiven the root of a binary tree, return the most frequent subtree sum. If there is a tie, return all the values with the highest frequency in any orde... Topics: Hash Table, Tree, Depth-First Search, Binary Tree
- 3844. Number of Ways to Assign Edge Weights I - Medium - Depth-First SearchThere is an undirected tree with n nodes labeled from 1 to n, rooted at node 1. The tree is represented by a 2D integer array edges of length n - 1, w... Topics: Math, Tree, Depth-First Search
- 1722. Throne Inheritance - Medium - Depth-First SearchA kingdom consists of a king, his children, his grandchildren, and so on. Every once in a while, someone in the family dies or a child is born. The ki... Topics: Hash Table, Tree, Depth-First Search, Design
- 3687. Longest Special Path - Hard - Depth-First SearchYou are given an undirected tree rooted at node 0 with n nodes numbered from 0 to n - 1, represented by a 2D array edges of length n - 1, where edges[... Topics: Array, Hash Table, Tree, Depth-First Search, Prefix Sum
- 1243. Sum of Nodes with Even-Valued Grandparent - Medium - Depth-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 - Depth-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 - Depth-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
- 1450. Delete Leaves With a Given Value - Medium - Depth-First SearchGiven a binary tree root and an integer target, delete all the leaf nodes with value target. Note that once you delete a leaf node with value target, ... Topics: Tree, Depth-First Search, Binary Tree
- 3829. Shortest Path in a Weighted Tree - Hard - Depth-First SearchYou are given an integer n and an undirected, weighted tree rooted at node 1 with n nodes numbered from 1 to n. This is represented by a 2D array edge... Topics: Array, Tree, Depth-First Search, Binary Indexed Tree, Segment Tree
- 1474. Longest ZigZag Path in a Binary Tree - Medium - Depth-First SearchYou are given the root of a binary tree. A ZigZag path for a binary tree is defined as follow: Choose any node in the binary tree and a direction (rig... Topics: Dynamic Programming, Tree, Depth-First Search, Binary Tree
- 799. Minimum Distance Between BST Nodes - Easy - Depth-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
- 933. Increasing Order Search Tree - Easy - Depth-First SearchGiven the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every no... Topics: Stack, Tree, Depth-First Search, Binary Search Tree, Binary Tree
- 3509. K-th Largest Perfect Subtree Size in Binary Tree - Medium - Depth-First SearchYou are given the root of a binary tree and an integer k. Return an integer denoting the size of the kth largest perfect binary subtree, or -1 if it d... Topics: Tree, Depth-First Search, Sorting, Binary Tree
- 1475. Maximum Sum BST in Binary Tree - Hard - Depth-First SearchGiven a binary tree root, return the maximum sum of all keys of any sub-tree which is also a Binary Search Tree (BST). Assume a BST is defined as foll... Topics: Dynamic Programming, Tree, Depth-First Search, Binary Search Tree, Binary Tree
- 2652. Count Number of Possible Root Nodes - Hard - Depth-First SearchAlice has an undirected tree with n nodes labeled from 0 to n - 1. The tree is represented as a 2D integer array edges of length n - 1 where edges[i] ... Topics: Array, Hash Table, Dynamic Programming, Tree, Depth-First Search
- 3439. Find Minimum Diameter After Merging Two Trees - Hard - Depth-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 - Depth-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
- 652. Find Duplicate Subtrees - Medium - Depth-First SearchGiven the root of a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only need to return the root node of any one ... Topics: Hash Table, Tree, Depth-First Search, Binary Tree
- 2568. Minimum Fuel Cost to Report to the Capital - Medium - Depth-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 - Depth-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
- 3112. Count Valid Paths in a Tree - Hard - Depth-First SearchThere is an undirected tree with n nodes labeled from 1 to n. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i]... Topics: Math, Dynamic Programming, Tree, Depth-First Search, Number Theory
- 1498. Find a Corresponding Node of a Binary Tree in a Clone of That Tree - Easy - Depth-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
- 1093. Recover a Tree From Preorder Traversal - Hard - Depth-First SearchWe run a preorder depth-first search (DFS) on the root of a binary tree. At each node in this traversal, we output D dashes (where D is the depth of t... Topics: String, Tree, Depth-First Search, Binary Tree
- 774. Maximum Depth of N-ary Tree - Easy - Depth-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
- 472. Concatenated Words - Hard - Depth-First SearchGiven an array of strings words (without duplicates), return all the concatenated words in the given list of words. A concatenated word is defined as ... Topics: Array, String, Dynamic Programming, Depth-First Search, Trie, Sorting
- 1653. Number of Good Leaf Nodes Pairs - Medium - Depth-First SearchYou are given the root of a binary tree and an integer distance. A pair of two different leaf nodes of a binary tree is said to be good if the length ... Topics: Tree, Depth-First Search, Binary Tree
- 1875. Tree of Coprimes - Hard - Depth-First SearchThere is a tree (i.e., a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. Each ... Topics: Array, Math, Tree, Depth-First Search, Number Theory
- 3386. Find Edges in Shortest Paths - Hard - Depth-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
- 2400. Minimum Score After Removals on a Tree - Hard - Depth-First SearchThere is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are given a 0-indexed integer array nums of length n w... Topics: Array, Bit Manipulation, Tree, Depth-First Search
- 606. Construct String from Binary Tree - Medium - Depth-First SearchGiven the root node of a binary tree, your task is to create a string representation of the tree following a specific set of formatting rules. The rep... Topics: String, Tree, Depth-First Search, Binary Tree
- 2583. Divide Nodes Into the Maximum Number of Groups - Hard - Depth-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
- 2104. Operations on Tree - Medium - Depth-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
- 2905. Count Paths That Can Form a Palindrome in a Tree - Hard - Depth-First SearchYou are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node 0 consisting of n nodes numbered from 0 to n - 1. The tree... Topics: Dynamic Programming, Bit Manipulation, Tree, Depth-First Search, Bitmask
- 2545. Height of Binary Tree After Subtree Removal Queries - Hard - Depth-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
- Breadth-First Search 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
- Design LeetCode Problems
- Divide and Conquer LeetCode Problems