Solution to Slalom-Skiing by codility

22 Oct

Question: Question Name: Slalom-Skiing or SlalomSkiing This is a wonderful variant of longest increasing subsequence.

Solution to Flood-Depth by codility

25 Sep

Question: 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.

Solution to Longest-Password by codility

22 Sep

Question: Question Name: Longest-Password or LongestPassword The solution could be more Pythonic with some additional space.

Solution to Sql-Sum by codility

21 Sep

Question: Question Name: Sql-Sum or SqlSum This question is too easy to be a serious training lesson. Most likely, it’s a live test for SQL challenges on The following solution works in both PostgreSQL and SQLite.

Solution to Contains Duplicate by LeetCode

20 Aug

Question: 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: 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: Question Name: Kth Largest Element in an Array This is exactly the quick-select.

Solution to Shortest Palindrome by LeetCode

8 Jun

Question: 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 Cyclic-Rotation by codility

9 Feb

Question: Question Name: Cyclic-Rotation or CyclicRotation With Python’s syntactic sugar, the solution is pretty short.

Well, kind of too easy. Let’s try a C++ solution to demo the details better. Thanks to @micropentium6, the original C++ solution is … Read More »