Skip to main content
53, Maximum Subarray

I Problem

Given an integer array nums, find the subarray with the largest sum, and return its sum.

Example 1
Input: nums = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
Output: 6
Explanation: The subarray [4, -1, 2, 1] has the largest sum 6.


MikeAbout 3 mingreedymediumarraydivide and conquerdynamic programming
109, Convert Sorted List to Binary Search Tree

I Problem

Given the head of a singly linked list where elements are sorted in ascending order, convert it to a height-balanced binary search tree.

Example 1

Input: head = [-10, -3, 0, 5, 9]
Output: [0, -3, 9, -10, null, 5]
Explanation: One possible answer is [0, -3, 9, -10, null, 5], which represents the shown height balanced BST.


MikeAbout 2 minbinary treemediumlinked listbinary treebinary search treedivide and conquer
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
654, Maximum Binary Tree

I Problem

You are given an integer array nums with no duplicates. A maximum binary tree can be built recursively from nums using the following algorithm:

  1. Create a root node whose value is the maximum value in nums.
  2. Recursively build the left subtree on the subarray prefix to the left of the maximum value.
  3. Recursively build the right subtree on the subarray suffix to the right of the maximum value.

MikeAbout 4 minbinary treemediumarraybinary treestackdivide and conquermonotonic stack
106, Construct Binary Tree from Post-order and In-order Traversal

I Problem

Given two integer arrays inorder and postorder where inorder is the inorder traversal of a binary tree and postorder is the postorder traversal of the same tree, construct and return the binary tree.

Example 1

Input: inorder = [9, 3, 15, 20, 7], postorder = [9, 15, 7, 20, 3]
Output: [3, 9, 20, null, null, 15, 7]


MikeAbout 3 minbinary treemediumarrayhash tabledivide and conquerbinary tree
105, Construct Binary Tree from Pre-order and In-order Traversal

I Problem

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.

Example 1

Input: preorder = [3, 9, 20, 15, 7], inorder = [9, 3, 15, 20, 7]
Output: [3, 9, 20, null, null, 15, 7]


MikeAbout 3 minbinary treemediumarrayhash tabledivide and conquerbinary tree
347, Top K Frequent Elements

I Problem

Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.

Example 1
Input: nums = [1, 1, 1, 2, 2, 3], k = 2
Output: [1, 2]


MikeAbout 4 minstack/queuemediumhash tabledivide and conquersortingheap(priority queue)bucket sortcountingquick select