Skip to main content
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
108, Convert Sorted Array to Binary Search Tree

I Problem

Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree.

Example 1

Input: nums = [-10, -3, 0, 5, 9]
Output: [0, -3, 9, -10, null, 5]
Explanation: [0, -10, 5, null, -3, null, 9] is also accepted:


MikeAbout 3 minbinary treeeasytreebinary treebinary search treearraydivide and conquer
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
429, N-ary Tree Level Order Traversal

I Problem

Given an n-ary tree, return the level order traversal of its nodes' values.

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

Example 1

Input: root = [1, null, 3, 2, 4, null, 5, 6]
Output: [[1], [3, 2, 4], [5, 6]]


MikeAbout 5 minbinary treemediumtreedepth first searchbreadth first search