Blog Posts

"..."
Medium
Algorithm Guide
Leetcode Problem
Python
String
Stack

The Problem:

Given a string s of '(' , ')' and lowercase English characters.

Your task is to remove the minimum number of '(' or ')' in any positions so that the resulting parentheses string is valid and return any valid string.

Formally, a parentheses string is valid if and only if:

  • It is the empty string, contains only lowercase characters, or
  • It can be written as AB (A concatenated with B), where A and B are valid strings, or
  • It can be written as (A), where A is a valid string.
Medium
Algorithm Guide
Leetcode Problem
Python
Binary Tree

The 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.

Return the maximum binary tree built from 'nums'.

"..."
Easy
Algorithm Guide
Leetcode Problem
Python
String

The Problem:

In an alien language, surprisingly they also use English lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters.

Given a sequence of words written in the alien language, and the order of the alphabet, return true if and only if the given words are sorted lexicographically in this alien language.

[
]
Easy
Algorithm Guide
Leetcode Problem
JavaScript

The Problem:

Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

[
]
Easy
Algorithm Guide
Leetcode Problem
JavaScript

The Problem:

You are given an array prices where prices[i] is the price of a given stock on the ith day.

You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.

Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.

[
]
Medium
Algorithm Guide
Leetcode Problem
JavaScript

The Problem:

Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.

[
]
Medium
Algorithm Guide
Leetcode Problem
JavaScript

The Problem:

Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). Find two lines, which, together with the x-axis forms a container, such that the container contains the most water.

Notice that you may not slant the container.

Minimum Remove to Make Valid Parentheses

Algorithm Guide
Leetcode Problem
Python
String
Stack
Medium
"..."

The Problem:

Given a string s of '(' , ')' and lowercase English characters.

Your task is to remove the minimum number of '(' or ')' in any positions so that the resulting parentheses string is valid and return any valid string.

Formally, a parentheses string is valid if and only if:

  • It is the empty string, contains only lowercase characters, or
  • It can be written as AB (A concatenated with B), where A and B are valid strings, or
  • It can be written as (A), where A is a valid string.

Maximum Binary Tree

Algorithm Guide
Leetcode Problem
Python
Binary Tree
Medium

The 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.

Return the maximum binary tree built from 'nums'.

Verifying an Alien Dictionary

Algorithm Guide
Leetcode Problem
Python
String
Easy
"..."

The Problem:

In an alien language, surprisingly they also use English lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters.

Given a sequence of words written in the alien language, and the order of the alphabet, return true if and only if the given words are sorted lexicographically in this alien language.

Maximum Subarray

Algorithm Guide
Leetcode Problem
JavaScript
Easy
[
]

The Problem:

Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

Best Time to Buy and Sell Stock

Algorithm Guide
Leetcode Problem
JavaScript
Easy
[
]

The Problem:

You are given an array prices where prices[i] is the price of a given stock on the ith day.

You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.

Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.

Merge Intervals

Algorithm Guide
Leetcode Problem
JavaScript
Medium
[
]

The Problem:

Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.

Container With The Most Water

Algorithm Guide
Leetcode Problem
JavaScript
Medium
[
]

The Problem:

Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). Find two lines, which, together with the x-axis forms a container, such that the container contains the most water.

Notice that you may not slant the container.