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…

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…

Question Simple task, reverse words in a sentence. Solution In Python, this can be simple because of the build-in functions. We can just split the sentence by spaces, reverse the list, and join them with spaces again. In C++, this can be complicated. The following might be one of the…

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次……

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 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=2pos+…

Question Define a stack structure with “min” function — a function to get the minimum value within the stack. The time complexity of min, push and pop functions must be O(1). Solution 結合鍊錶一起做。首先我做插入以下數字: 10, 7, 3, 3, 8, 5, 2, 6 0: 10 -> NULL (MIN=10, POS=…

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…

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

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]…