## Unable to install Homebrew

Unable to install Homebrew with this? ruby -e “\$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)” What’s happened -e:70: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777 ==> This script will install: /usr/local/bin/brew /usr/local/Library/… /usr/local/share/man/man1/brew.1 Press RETURN to continue or any other key to abort ==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew Password: ==> Downloading and installing Homebrew… remote: Counting objects:…

## Interview Practice Extra 07 – Universal Value Binary Tree

Question Design an algorithm to verify that a tree is a universal value binary tree. Universal value binary tree means all value in that tree is the same. Solution There is two approach for this problem. One is with recursive function and another is with iterative function. For this problem, iterative function makes simpler answer. However,…

## Interview Practice Extra 06 – Vending Machine

Question This is an actual question I encountered in an Amazon phone interview in November 2013. You are going to design the money changing algorithm for a vending machine. That is, after any purchase, the machine makes change to users with a combination of coins. And the machine only have 3 types of coins: nickel…

## Interview Practice 09 – Verify Post-order Sequence of BST

Construct an algorithm to verify if a set of numbers is the post-order search result of a binary search tree.

## Interview Practice 07 – Determine if Two Linked Lists Intersect

Question Given 2 linked list head pointers, determine whether they intersect at some point. Solution First of all, linked list can have loop or not, and this gives 3 possible situations. 1. For the 2 loops head pointer 1 and head pointer 2, move pointer 1 at normal speed, and pointer 2 at double speed….

## 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);…

## 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) {}…

## Interview Practice 03 – Longest Sequence that Makes the Greatest Sum

Question 输入一个整形数组，数组里有正数也有负数。 数组中连续的一个或多个整数组成一个子数组，每个子数组都有一个和。 求所有子数组的和的最大值。要求时间复杂度为O(n)。 例如输入的数组为1, -2, 3, 10, -4, 7, 2, -5，和最大的子数组为3, 10, -4, 7, 2， 因此输出为该子数组的和18。 From a set of positive and negative integers, find the longest sequence that makes the greatest sum. It is required to have the time complexity of O(n). Solution 如输入的数组为1, -2, 3, 10, -4, 7, 2, -5， 那么最大的子数组为3, 10,…