Description LeetCode 621 Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task could be done in one interval. For each interval, CPU could finish one task or just be idle. However, there is

## Stable Matching

Problem Input: Two set of equal size + the preferences of each element Goal: Find a perfect stable matching We can formulating the problem as a stable marriage problem. Given $$n$$ men and $$n$$ women, find a stable matching. Each man lists women in order of preference from best to worst. So as each woman.

Description LeetCode 127 Given two words (beginWord and endWord), and a dictionary’s word list, find the length of shortest transformation sequence from beginWord to endWord, such that: Only one letter can be changed at a time. Each transformed word must exist in the word list. Note that beginWord is not a transformed word. Note: Return 0 if there is no such transformation sequence. All

## Populating Next Right Pointers in Each Node II

Description LeetCode 117 Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL. Initially, all next pointers are set to NULL. Note: You may only use constant

## Binary Tree Maximum Path Sum

Description LeetCode 124 Given a non-empty binary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must contain at least one node and does not need to go through the root. Example 1: Input:

## Distinct Subsequences

Description LeetCode 115 Given a string S and a string T, count the number of distinct subsequences of S which equals T. A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, “ACE” is a subsequence of “ABCDE” while “AEC” is not).

## Convert Sorted List to Binary Search Tree

Description LeetCode 109 Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. Example: Given the sorted linked

## First Missing Positive

Description LeetCode 41 Given an unsorted integer array, find the smallest missing positive integer. Example 1: Input: [1,2,0] Output: 3 Example 2: Input: [3,4,-1,1] Output: 2 Example 3: Input: [7,8,9,11,12] Output: 1 Note: Your algorithm should run in O(n) time and uses constant extra space. Analysis From the description, we can find an important clue that the

## Recover Binary Search Tree

Description LeetCode 99 Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Example 1: Input: [1,3,null,null,2]   1   /  3   \   2 Output: [3,1,null,null,2]   3   /  1   \   2 Example 2: Input: [3,1,4,null,null,2] 3 / \ 1 4

## Construct all possible BSTs for keys 1 to N

Description LeetCode 95 Given an integer n, generate all structurally unique BST’s (binary search trees) that store values 1 … n. Example: Input: 3 Output: [   [1,null,3,2],   [3,2,null,1],   [3,1,null,null,2],   [2,1,3],   [1,null,2,null,3] ] Explanation: The above output corresponds to the 5 unique BST’s shown below: 1 3 3 2 1 \ / / / \