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

20 Apr

In the book, the author introduces many different methods. As the author indicates, the two-pointer iterative solution is the best. In contrast, the recursive method is less effective but quite interesting. It might be useful in some cases. I only … Read More »

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

16 Apr

There are two solutions for this question. The first one is with hash table, thus needs more space but less time. The second one needs no additional space but more time. In the first solution, I choose to use the … Read More »

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

12 Apr

If string str1 is a rotation of string str2, it must holds two conditions: The length of str1 equals to the length of str2; There is at least a set of two string A and B, such that str1=AB and … Read More »

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

23 Mar

In this question, we have to travel the matrix twice. In the first time, we need to record which rows and columns contain zero element. And in the second round, we will set these rows and columns entirely zero. By … Read More »

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

22 Mar

This question asks us to rotate an N by N matrix. Each element in the matrix is a pixel of an image, and represented by 4 bytes. The question did not indicate the length of byte. And I assume the … Read More »

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

20 Mar

Generally, this question requires us to do a length encoding of an string. For example, after compression, the string “aaaabb” should become “a4b2”. If the compression could not shorten the string, the program will leave original string unchanged. I solve … Read More »

## Find a Duplicate Item In an Array of Shuffled Consecutive Integers

16 Mar

Question: if you hava an array with n integers. These integers are in random order. And each interger is between 1 and n-1, including 1 and n-1. Additionally, there is one and only one integer, which appears twice, while all … Read More »

## Some Methods to Get the Number of Digits in An Integer, and Their Performance (2)

6 Mar

In this article, an stable-cost method is proposed and tested. Previously, the test result showed, the performance of brute force method is the best. Let the number of digits be n. In the best case, in which the integer is … Read More »

## Some Methods to Get the Number of Digits in An Integer, and Their Performance

16 Feb

Sometimes, we need to know the number of digits in an integer. There are many methods, which could do this work well. Here we list some of them, and compare their performance in different circumstances. Firstly, we post the source … Read More »

9 Feb