Skip to main content
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
145, Binary Tree Post-order Traversal

I Problem

Given the root of a binary tree, return the postorder traversal of its nodes' values.

Example 1

Input: root = [1, null, 2, 3]
Output: [3, 2, 1]
Explanation:

Example 2
Input: root = []
Output: []


MikeAbout 3 minbinary treeeasystackbinary treedepth first search
94, Binary Tree In-order Traversal

I Problem

Given the root of a binary tree, return the inorder traversal of its nodes' values.

Example 1

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

Example 2
Input: root = []
Output: []

Example 3
Input: root = [1]
Output: [1]


MikeAbout 2 minbinary treeeasystackbinary treedepth first search
144, Binary Tree Pre-order Traversal

I Problem

Given the root of a binary tree, return the preorder traversal of its nodes' values.

Example 1

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

Example 2
Input: root = []
Output: []

Example 3
Input: root = [1]
Output: [1]


MikeAbout 2 minbinary treeeasystackbinary treedepth first search
1047, Remove All Adjacent Duplicates In String

I Problem

You are given a string s consisting of lowercase English letters. A duplicate removal consists of choosing two adjacent and equal letters and removing them.

We repeatedly make duplicate removals on s until we no longer can.


MikeAbout 1 minstack/queueeasystringstack
20, Valid Parentheses

I Problem

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

An input string is valid if:

  1. Open brackets must be closed by the same type of brackets.
  2. Open brackets must be closed in the correct order.
  3. Every close bracket has a corresponding open bracket of the same type.

MikeAbout 1 minstack/queueeasystringstack
225, Implement Stack using Queues

I Problem

Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack (push, top, pop, and empty).

Implement the MyStack class:

  • void push(int x) Pushes element x to the top of the stack.
  • int pop() Removes the element on the top of the stack and returns it.
  • int top() Returns the element on the top of the stack.
  • boolean empty() Returns true if the stack is empty, false otherwise.

MikeAbout 2 minstack/queueeasystackqueuedesign
232, Implement Queue using Stacks

I Problem

Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty).

Implement the MyQueue class:

  • void push(int x) Pushes element x to the back of the queue.
  • int pop() Removes the element from the front of the queue and returns it.
  • int peek() Returns the element at the front of the queue.
  • boolean empty() Returns true if the queue is empty, false otherwise.

MikeAbout 2 minstack/queueeasystackqueuedesign
844, Backspace String Compare

I Problem

Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character.

Note that after backspacing an empty text, the text will continue empty.

Example 1:
Input: s = "ab#c", t = "ad#c"
Output: true
Explanation: Both s and t become "ac".


MikeAbout 2 minarrayeasyarraytwo pointersstackstring
2