Wednesday, January 7, 2015

[Interview]Zillow Coding Test




Question 1) Given a string, write a routine that converts the string to a long, without using the
built in functions that would do this. Describe what (if any) limitations the code has. 

Question 2) Implement insert and delete in a tri-nary tree. A tri-nary tree is much like a binary
tree but with three child nodes for each parent instead of two -- with the left node being values
less than the parent, the right node values greater than the parent, and the middle nodes values
equal to the parent.

都是以前做过题目的变形,第一题可以参考String to Integer,第二题参考Remove Node in BST。Trinary树删除的区别就是注意我们有duplicates尽量先删duplicates,没有duplicates才用BST删除的方法,deleteMin中也是一样的。

代码如下,包括自己写的test case:

String to Long


Trinary Tree


1 comment:

  1. 你delete 不对吧 如果有这个树 你要把9删了,findMin(9) 会返回 Node 11,
    然后你再设node.right = node, 11.right = 11 这违法规定了
    7
    \
    9
    / \
    6 11
    |
    11

    ReplyDelete