## Solution to Closest Binary Search Tree Value II

5 May

This question is available on both Leetcode (No. 270) and Lintcode (No. 901). The question is not too hard, if we do not chase the best time complexity. For example, we can traversal all the nodes and book-keep the closest … Read More »

## Solution to Contains Duplicate by LeetCode

20 Aug

Question: https://leetcode.com/problems/contains-duplicate/ Question Name: Contains Duplicate In general, I found two solutions. The first solution is using hash set:

The second solution is using sorting. We could sort the input and check each pair of adjacent items. Or we could early … Read More »

## Solution to Combination Sum III by LeetCode

15 Aug

Question: https://leetcode.com/problems/combination-sum-iii/ Question Name: Combination Sum III This is a typical recursion problem. Find out the base case and recursive cases, and that’s the right solution.

## Solution to Kth Largest Element in an Array by LeetCode

10 Jun

Question: https://leetcode.com/problems/kth-largest-element-in-an-array/ Question Name: Kth Largest Element in an Array This is exactly the quick-select.

## Solution to Shortest Palindrome by LeetCode

8 Jun

Question: https://leetcode.com/problems/shortest-palindrome/ Question Name: Shortest Palindrome This is a variant of Longest Palindromic Substring. The key point is to convert the original question as following: 1. Shortest Palindrome by adding any characters in the head.  Therefore the original string “original” is going … Read More »

## Solution to House Robber II by LeetCode

3 Feb

Question: https://leetcode.com/problems/house-robber-ii/ Question Name: House Robber II This is a variant of House Robber. We need to apply the previous solution to two sub-arrays and return the maximum of the two results: 1. Do not use the first element, and … Read More »

## Solution to Word Search II by LeetCode

1 Feb

Question: https://leetcode.com/problems/word-search-ii/ Question Name: Word Search II In general, this is a question with DFS/BFS of graph. Additionally, we need some optimizations: Use prefix tree to terminate the search early; Remove the found word in the prefix tree; Use bigrams … Read More »

## Solution to Add and Search Word – Data Structure Design by LeetCode

8 Jan

Question: https://leetcode.com/problems/add-and-search-word-data-structure-design/ Question Name: Add and Search Word – Data Structure Design This is a variant of prefix tree (trie).

## Solution to Course Schedule II by LeetCode

3 Jan

Question: https://leetcode.com/problems/course-schedule-ii/ Question Name: Course Schedule II

## Solution to Minimum Size Subarray Sum by LeetCode

1 Jan

Question: https://leetcode.com/problems/minimum-size-subarray-sum/ Question Name: Minimum Size Subarray Sum This question is very similar with Longest Substring Without Repeating Characters and Minimum Window Substring.