Skip to main content

52 docs tagged with "Depth-First Search"

View all tags

Array Nesting

This is a solution to the Array Nesting problem on LeetCode.

Battleships in a Board

Given an `m x n` board where each cell is a battleship 'X' or empty '.', count the number of battleships on the board.

Cat and Mouse

This is a solution to the Cat and Mouse problem on LeetCode.

Construct String from Binary Tree

Given the root of a binary tree, construct a string consisting of parenthesis and integers from a binary tree with the preorder traversal way.

Convert BST to Greater Tree

Given 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 the sum of all keys greater than the original key in BST.

Counting Visible Nodes in Binary Tree

Given a binary tree, count the number of visible nodes. A node is considered visible if, in the path from the root to that node, there are no nodes with a greater value.

Course Schedule

This document provides a solution to the Course Schedule problem.

Delete Nodes And Return Forest

Solve the problem of deleting nodes from a binary tree and returning the forest of remaining trees using depth-first search.

Flood Fill

This is a solution to the Flood Fill problem on LeetCode.

Loud and Rich

Return an integer array answer where answer[x] = y indicates that y is the person with the least quietness among all individuals who have equal to or more money than person x.

Merge Two Binary Trees

Given two binary trees, merge them into a new binary tree by adding the values of overlapping nodes.

Mini Parser

This is a solution to the Mini Parser problem on LeetCode.

Most Frequent Subtree Sum

Given 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 order.

Path Sum

Given 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 path equals targetSum.

Path Sum III

This is a solution to the Path Sum III problem on LeetCode.

Path Sum-II

Given 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. Each path should be returned as a list of the node values, not node references.

Subtree of Another Tree(LeetCode)

Given 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 false otherwise.

Sum root to leaf numbers

You 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.