## Solution to Cyclic-Rotation by codility

9 Feb

Question: https://codility.com/demo/take-sample-test/cyclic_rotation/ 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 »

## Solution to Reverse Words in a String by LeetCode

27 Jul

Question: https://oj.leetcode.com/problems/reverse-words-in-a-string/ Question Name: Reverse Words in a String To solve it with Python, it is as simple as one statement.

But is there a better way? Anyone, who read the excellent book Programming Pearls before, might rememberÂ Doug McIlroy’s … Read More »

## Solution to Distinct by codility

18 Mar

Question: https://codility.com/demo/take-sample-test/distinct Question Name: Distinct In this question, the expected worst-case time complexity is O(N*log(N)). Thus the designed, or says official, solution would be sort the input and travel them. This solution is practically good. And it is shown as … Read More »

## Unofficial C Solution to Problem 3.4 in Cracking the Coding Interview (5th Edition)

13 Oct

Before solving this problem, we introduce a simple library of stack with integers. Many following questions need an integer stack. Not to reinvent the wheel in our following solutions, we make a standalone integer stack library. Actually, we should do … Read More »

## Unofficial C Solution to Problem 3.3 in Cracking the Coding Interview (5th Edition)

10 Oct

The first part of this question is easy: use a set of stacks to mimic a single stack. In the second part, we need to implement a new method as popAt(int index) to make a pop operation on a specific … Read More »

## Unofficial C Solution to Problem 3.2 in Cracking the Coding Interview (5th Edition)

31 Jul

In my solution, I used a structure with two traditional stacks. One of them is used to store the original elements. The other is used to store the latest minimum elements. At any time, the top element in the second … Read More »

## Unofficial C Solution to Problem 3.1 in Cracking the Coding Interview (5th Edition)

19 Jul

I used a different solution from the ones in the original book. In the first official solution in the book, one stack might be full while another is empty. The space utilization is bad. In the second official solution, once … Read More »

## Unofficial C Solution to Problem 2.7 in Cracking the Coding Interview (5th Edition)

11 May

There is a similar and easier question: how to check if an array is a palindrome? Or equivalently, how to check if a double linked list is a palindrome? The three solutions in the original question work well for these … Read More »

## Unofficial C Solution to Problem 2.6 in Cracking the Coding Interview (5th Edition)

10 May

There is a follow up question: how to determine whether two linked lists, to say list1 and list2, intersect each other. Two solutions are available for this problem. On one hand, we could link the end of list1 to the … Read More »

## Unofficial C Solution to Problem 2.5 in Cracking the Coding Interview (5th Edition)

9 May

The official solution for the backward problem is quite good. In contrast, there are two improvable places in the official solution for the forward problem (the follow up question). On one hand, in the official implement, the list is double … Read More »