Interview Practice Basic – Breathe First Traversal

In the iterative way You can only do breathe first traversal in iterative way. Though you can still make it recursive by calling itself in each loop, but you will not benefit from it. It is similar to doing depth first traversal, instead you use a FIFO queue to store the nodes. Node definition static…

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 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 11 – Greatest Distance Between Two Nodes in Binary Tree

Get the greatest distance between two nodes in a binary tree. Assume links between nodes are bidirectional. Distance is defined as the amount of nodes connected along the path linked two nodes.

Read more...

Find the User Agent Strings of any Mobile Devices

It’s quite often for a developer to make use of the user agent to determine what browser does a user used, especially for those who develop web services and websites. Recently I found a website which has a huge database of mobile device information, including the user agent string and even the functions supported in…

Read more...