📄️ Guidelines
Most of the problems in the category deal with trees since we have use dfs to solve most of those problems.
📄️ Invert A Binary Tree
Given the root of a binary tree, invert the tree, and return its root.
📄️ Symmetric Tree
Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).
📄️ Same Tree
Given the roots of two binary trees p and q, write a function to check if they are the same or not.
📄️ Subtree of Another Tree
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.
📄️ Merge Two Binary Trees
Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge the two trees into a new binary tree.
📄️ Maximum Depth of Binary Tree
Given the root of a binary tree, return its maximum depth.
📄️ Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.
📄️ 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.
📄️ Convert Sorted Array to Binary Search Tree
Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree
📄️ Diameter of Binary Tree
Given the root of a binary tree, return the length of the diameter of the tree.
📄️ Flood Fill
An image is represented by an m x n integer grid image where image[i][j] represents the pixel value of the image.
📄️ Lowest Common Ancestor of a Binary Tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.
📄️ Validate Binary Search Tree
Given the root of a binary tree, determine if it is a valid binary search tree (BST).
📄️ Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST.
📄️ Maximum Binary Tree
You are given an integer array nums with no duplicates. A maximum binary tree can be built recursively from nums using the following algorithm...
📄️ 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.
📄️ Path Sum III
Given 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.
📄️ Construct Binary Tree from Preorder and Inorder Traversal
Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree.
📄️ All Nodes Distance K in Binary Tree
Given 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 k from the target node.
📄️ Kth Smallest Element in a BST
Given 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.
📄️ Binary Tree Maximum Path Sum
A 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 in the sequence at most once.
📄️ Serialize and Deserialize Binary Tree
Design an algorithm to serialize and deserialize a binary tree.
📄️ Longest Increasing Path in a Matrix
Given an m x n integers matrix, return the length of the longest increasing path in matrix.