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

Read more...

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

Read more...

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…

Read more...

Interview Practice 28 – Counting One in Binary Expression

Question Given a number, find the number of 1 in the number’s binary expression. For example, binary express of 10 is 1010. So the number of 1 in it is 2. Solution To solve this, we can check each bit by shifting the bits one by one. 1. 1010 -> check 0 2. 101 -> check…

Read more...

Interview Practice 26 – String Right-rotation

Question Write a program to right-rotate a string by m characters. Right-rotating a string means moving m characters at the left of string to the right. Is it required the time complexity is O(n) and helper memory size is O(1). For example, right-rotate “abcdefghi” by 3 characters gives “defghiabc”. Solution There are 2 ways to…

Read more...

Interview Practice 24 – Reverse a Linked List

Question Reverse a linked list. Sample # node structure class Node: value = None next = None def __init__(self, value, next_node=None): self.value = value self.next = next_node # reverse the linked list and return the head node def reverse_linked_list(head): reversed_head = None last_node = None node = head while node: next_node = node.next if next_node…

Read more...

Interview Practice 22 – Card Guessing

Question Consider there are 4 blue and 4 red cards. Host gets 2 cards randomly, no one knows what cards they are. Then he places 2 random cards at the forehead of each player A, B and C. Players do not know the color of their own cards, but know those of other players. They…

Read more...

Interview Pizzle 1 – Find the Heavier Marble

Question You have 9 marbles. 8 marbles weigh 1 ounce each, & one marble weighs 1.5 ounces. You are unable to determine which is the heavier marble by looking at them. You have a weighing scale that consists of 2 pans, but the scale is only good for 2 total weighings. How can you determine which marble is the heaviest…

Read more...

Interview Practice 20 – Convert String to Integer

Question Convert the inputted string to an integer. For example, “345” will output 345. Solution Though it looks simple, in fact it is pretty tricky. First we need to make the concept clear. 1. Scan each character from the left to right, then multiply the previously obtained integer by ten before adding the scanned digit…

Read more...