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 Extra 05 – Identify Prime Numbers

Question Write an algorithm to identify prime numbers from a list of numbers ranging 0-100. Solution The main question is actually to write a program to check if a number is prime. There are 4 situations. 1. If number is 0 or 1, it is not prime. 2. if the number is 2, it is…

Read more...

Interview Practice Extra 04 – Remove Node from Singly Linked List

Question How do you remove a node from a singly linked list, given only that node? Head node is not given. Solution Set next of this node to the next of the next node. node->next = node->next->next; Reference Glassdoor

Read more...

Interview Practice Extra 03 – Verify Binary Tree with Same Value

Question Verify whether all nodes have the same value in a binary tree. Solution We can traverse the tree with our usual way, like depth-first or breadth-first algorithm. Then pass a value, probably the root value, to compare with the visiting node. Example # node structure class bst_node: value = None left = None right…

Read more...

Interview Practice Extra 02 – Duplicates in List

Question Write an algorithm to remove duplicated node from a linked list. Solution There are many ways to do it. For the first one, as the simplest one, we could use 2 loops to compare each element with all other elements. However, this takes forever: O(n²). The second way Reference http://www.geeksforgeeks.org/remove-duplicates-from-an-unsorted-linked-list/

Read more...

Interview Practice Extra 01 – Find Loop in Linked List

Question Validate a linked list whether there is a loop in it. That is, there is a node in a linked list with  the next pointer pointing to a node ahead in the same linked list. This is the question I encountered in 2013 spring, from a Yahoo phone interview. Solution Define 2 pointers pointing to…

Read more...

Mbox Mail for Mac is actually working on Lion

Once I thought the Mbox Mail for Mac doesn’t work in Lion. The reason is that when I use the same setting in Thurderbird, i can receive emails. This made me ensure the problem comes from the new Apple Mail 5. I dug into the protocol IMAP, learnt the commands used in it. After that…

Read more...

Convert character encoding in PHP

Usually while we extract information from other websites, character encoding might not correct. For example, j-jis.com is encoded with Shift-JIS. Therefore if your MySQL charset is UTF-8, it causes incorrect information. To handle the changing of character encoding, we can use iconv in PHP. [sourcecode language=”php”] $url = "http://j-jis.com/"; $html = file_get_contents($url); $html = preg_replace("/rn|n|t/",…

Read more...