## 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 »

## A Simple Expiring Set in Python

17 Jan

Months ago, I coded a tiny crawler to monitor some electronics deals. I extracted a list of my target products from the homepage, and on each product page tried to add it to my cart. Basically I need to: Check … Read More »

## Solution to Rectangle-Builder-Greater-Area by codility

20 Nov

Question: https://codility.com/demo/take-sample-test/rectangle_builder_greater_area/ Question Name: Rectangle-Builder-Greater-Area or RectangleBuilderGreaterArea This key is the binary search.

## Solution to Dwarfs-Rafting by codility

19 Nov

Question: https://codility.com/demo/take-sample-test/dwarfs_rafting/ Question Name: Dwarfs-Rafting or DwarfsRafting Need some simple mathematical knowledge. The code is unnecessarily long. A 2-d array is better to write much shorter code. However, I keep the long version for better readability.

## Solution to Slalom-Skiing by codility

22 Oct

Question: https://codility.com/programmers/lessons/90-tasks_from_indeed_prime_2015_challenge/slalom_skiing/ Question Name: Slalom-Skiing or SlalomSkiing This is a wonderful variant of longest increasing subsequence. Because the longest increasing subsequence is a very classic question withe O(NlogN) solution, the key point to solve this question is to covert its original form … Read More »

## Solution to Flood-Depth by codility

25 Sep

Question: https://codility.com/demo/take-sample-test/flood_depth/ Question Name: Flood-Depth or FloodDepth This is a variant of Trapping Rain Water by LeetCode. The undergoing concept is the same. However, the implementation is a bit different.

22 Sep

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