Skip to main content
968, Binary Tree Cameras

I Problem

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

Return the minimum number of cameras needed to monitor all nodes of the tree.


MikeAbout 3 mingreedyhardbinary treedepth first searchdynamic programming
332, Reconstruct Itinerary

I Problem

You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.

All of the tickets belong to a man who departs from "JFK", thus, the itinerary must begin with "JFK". If there are multiple valid itineraries, you should return the itinerary that has the smallest lexical order when read as a single string.


MikeAbout 2 minbacktrackingmediumdepth first searchgraphbacktracking
559, Maximum Depth of N-ary Tree

I Problem

Given 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 leaf node.

Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).


MikeAbout 3 minbinary treeeasytreedepth first searchbreadth first search
572, Subtree of Another Tree

I Problem

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.

A subtree of a binary tree tree is a tree that consists of a node in tree and all of this node's descendants. The tree tree could also be considered as a subtree of itself.


MikeAbout 3 minbinary treeeasybinary treedepth first searchstring matchinghash function
100, Same Tree

I Problem

Given 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 are structurally identical, and the nodes have the same value.

Example 1

Input: p = [1, 2, 3], q = [1, 2, 3]
Output: true


MikeAbout 2 minbinary treeeasybinary treedepth first searchbreadth first search
669, Trim a Binary Search Tree

I Problem

Given 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, high]. Trimming the tree should not change the relative structure of the elements that will remain in the tree (i.e., any node's descendant should remain a descendant). It can be proven that there is a unique answer.


MikeAbout 2 minbinary treemediumbinary treebinary search treedepth first search
235, Lowest Common Ancestor of a Binary Search Tree

I Problem

Given 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 Wikipedia: "The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself)."


MikeAbout 4 minbinary treemediumtreebinary treebinary search treedepth first search
236, Lowest Common Ancestor of a Binary Tree

I Problem

Given 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 lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself)."


MikeAbout 2 minbinary treemediumbinary treedepth first search
538, Convert BST to Greater Tree

I Problem

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.

As a reminder, a binary search tree is a tree that satisfies these constraints:


MikeAbout 3 minbinary treemediumbinary treedepth first searchbinary search tree
501, Find Mode in Binary Search Tree

I Problem

Given 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 has more than one mode, return them in any order.


MikeAbout 5 minbinary treeeasybinary treedepth first searchbinary search tree
2
3
4