Interview Practice Basic – Snapsack Problem

Snapsack problem refers to the situation you want to find a combination of items that can fill up a container. Each items should be attached with a value, and there should be a target value that means a container is filled up. For example, a container has 25 spaces and there are items that will…

Read more...

Interview Practice 21 – Summing Combinations

Question Given a integers m and n, generate all combination within 1 to n that would give the sum m. For example, for m=5 and n=5, the combinations are {5}, {4+1}, {3+2}. Solution This is a knapsack problem. # knapsack that store the found combination knapsack = array # find combination of 1..n with sum target…

Read more...

Interview Practice 10 – Reverse Sentence

Simple task, reverse words in a sentence.

Read more...

Interview Practice 06 – Appearance Count of Numbers

Question 腾讯面试题: 给你10分钟时间,根据上排给出十个数,在其下排填出对应的十个数 要求下排每个数都是先前上排那十个数在下排出现的次数。 上排的十个数如下: 【0,1,2,3,4,5,6,7,8,9】 Solution 初看此题,貌似很难,10分钟过去了,可能有的人,题目都还没看懂。 举一个例子, 数值: 0,1,2,3,4,5,6,7,8,9 分配: 6,2,1,0,0,0,1,0,0,0 0在下排出现了6次,1在下排出现了2次, 2在下排出现了1次,3在下排出现了0次…. 以此类推.. Sample Code [expand title=”Sample Code in C++” tag=”h4″] //数值: 0,1,2,3,4,5,6,7,8,9 //分配: 6,2,1,0,0,0,1,0,0,0 #include <iostream> using namespace std; #define len 10 class NumberTB { private: int top[len]; int bottom[len]; bool success; public: NumberTB(); int* getBottom(); void setNextBottom(); int getFrequecy(int num);…

Read more...

Interview Practice 05 – K Smallest Elements in List

Question 输入n个整数,输出其中最小的k个。 例如输入1,2,3,4,5,6,7和8这8个数字, 则最小的4个数字为1,2,3和4。 Sample Code [expand title=”Sample Code in C++” tag=”h4″] #include <iostream> using namespace std; class MinK { private: int *array; int size; void shiftDown(int *ret,int pos,int length) { int t=ret[pos]; for(int s=2*pos+1;s<=length;s=2*s+1) { if(s<length&&ret[s]<ret[s+1]) ++s; if(t<ret[s]) { ret[pos]=ret[s]; pos=s; } else break; } ret[pos]=t; } public: MinK(int *arr,int si): array(arr), size(si) {}…

Read more...

Interview Practice 02 – Stack with Minimum Function

定義棧的數據結構,要求添加一個min函數,能夠得到棧的最小元素。要求函數min、push以及pop的時間複雜度都是O(1)。

Read more...

External directory in Xampp (Apache)

For both server and website developing, I usually use Xampp’s Apache to create a localhost server. However, I hate to put my important files in the htdocs inside Apache. Instead I would rather put the folder inside Documents, and make a link to htdocs. First, create a symbolic link from your actual folder to htdocs….

Read more...

Show completions and quick help tips in Xcode

I know it is troublesome, tedious, or just like hell. Apple has his own way to do a common task. Very often, we need to use the autocompletion in IDE to assist coding so we do not need to memorize the billions of function names. In Eclipse, everything is automatic. A list of function names linked together…

Read more...

Dynamic array in VBA

We can easy resize the array declared in VBA. The trick is actually relocate the array to a bigger space. Suppose we need an array, we have to declare (dim) it with unknown size. It can be any variant (string, integer, etc…): [sourcecode language=”vb”]Dim MyArray() As String[/sourcecode] We we need to add something new to…

Read more...