由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Twitter实习第二轮电面总结
相关主题
Linkedin 电面面经,已跪,求分析是不是被黑。我想了想
感恩发面经-Amazon第二轮电面BST合并的面试题
A M onsite相继被拒 伤心之余附上面经和总结, 顺便求refer一个GOOG的二叉树面试题
snapchat以及FLG 面经(已挂)问一道旧题
求教一道老题google电面
MS面试题谷歌 电面
今天面试惨败,分享面经cs菜鸟的找工经历
BST面试题微软 intern offer
相关话题的讨论汇总
话题: end话题: parent话题: two话题: ruby话题: 然后
进入JobHunting版参与讨论
1 (共1页)
l****p
发帖数: 397
1
面试官从口音可以听出来是个阿三哥。
一开始先问我的学历,然后问我熟悉哪些编程语言和技术。然后开始写程序。
面试官写了一小段程序:
class A
def foo
puts "hello"
end
end
class B < A
def foo
puts "world"
end
end
s = B.new
s.foo
然后问我这时打印出什么,我说是"world",然后问我说怎么让s打印出"hello",写代
码实现。我心想这问题也太白痴了吧:
s = A.new
s.foo
然后他说s必须是B的对象。我明白了他要让我调用父类方法,但我一时忘了Ruby怎么调
父类方法了,于是绕开,说Ruby允许重新打开了个类去重定义它的方法:
class B < A
def foo
puts "hello"
end
end
然后他又说如果不要重定义呢。这下没招了,于是把最早的B.foo的定义里写了个super
,说我忘了Ruby怎么调父类了,我可以查一下。他说不用了,这就是他所期望了。(面
试后查了一下,Ruby调父类方法就是用super,这下真是歪打正着)
接下来:Find the first common parent in a tree。哈哈,《Programming
Interviews Exposed》原题啊,于是大概解释一下思路就开始编码:
def common_parent(node, one, two)
if (node.key > one and node.key < two) or (node.key > two and node.key <
one)
return node.key
elsif node.key > one and node.key > two
return common_parent(node.left_child, one, two)
else
return common_parent(node.right_child, one, two)
end
end
用面试官提的例子稍微检查一下,发现可用,然后跟他说如果是实际程序我就写个unit
test。面试官又举出了另一个例子,其中one是two的parent。我检查了一下,确实在
等于的时候不对。于是在第一个if后面的所有不等号都加上等号,然后说这下可以了,
这时返回one。他说不是,应该返回one的parent。我心想,我怎么记得应该是one呢,
好吧,你说怎么样就怎么样。于是把特殊情况挑出来,在最前面加上:
if node.key == one or node.key == two
return node.parent.key
end
然后把刚才加的等号去掉。这下面试官说I like that。
接下来问我对unix/linux熟悉不,我说我平常就是用Ubuntu在写程序,但我对shell编
程不熟。他问写简单的bash script呢,我说我会把几个命令放在一起,但如果要加上
if, loop等我就不熟了。他问如果让你写bash script,are u comfortable with that
,我说我可以学,I like Linux more than Windows。他说it's great to hear that.
(看来Twitter对unix/linux很看重啊,两次面试都被问到这个。)
然后就结束了,也没让我问问题。我看他是个build&release engineer,本来还想问他
关于Twitter怎么build&release。总共才花了30 min
z*****n
发帖数: 447
2
第二题看你的解法,应该是Find the first common parent in a BST吧
l****p
发帖数: 397
3
是的

【在 z*****n 的大作中提到】
: 第二题看你的解法,应该是Find the first common parent in a BST吧
l****p
发帖数: 397
4
面试官从口音可以听出来是个阿三哥。
一开始先问我的学历,然后问我熟悉哪些编程语言和技术。然后开始写程序。
面试官写了一小段程序:
class A
def foo
puts "hello"
end
end
class B < A
def foo
puts "world"
end
end
s = B.new
s.foo
然后问我这时打印出什么,我说是"world",然后问我说怎么让s打印出"hello",写代
码实现。我心想这问题也太白痴了吧:
s = A.new
s.foo
然后他说s必须是B的对象。我明白了他要让我调用父类方法,但我一时忘了Ruby怎么调
父类方法了,于是绕开,说Ruby允许重新打开了个类去重定义它的方法:
class B < A
def foo
puts "hello"
end
end
然后他又说如果不要重定义呢。这下没招了,于是把最早的B.foo的定义里写了个super
,说我忘了Ruby怎么调父类了,我可以查一下。他说不用了,这就是他所期望了。(面
试后查了一下,Ruby调父类方法就是用super,这下真是歪打正着)
接下来:Find the first common parent in a tree。哈哈,《Programming
Interviews Exposed》原题啊,于是大概解释一下思路就开始编码:
def common_parent(node, one, two)
if (node.key > one and node.key < two) or (node.key > two and node.key <
one)
return node.key
elsif node.key > one and node.key > two
return common_parent(node.left_child, one, two)
else
return common_parent(node.right_child, one, two)
end
end
用面试官提的例子稍微检查一下,发现可用,然后跟他说如果是实际程序我就写个unit
test。面试官又举出了另一个例子,其中one是two的parent。我检查了一下,确实在
等于的时候不对。于是在第一个if后面的所有不等号都加上等号,然后说这下可以了,
这时返回one。他说不是,应该返回one的parent。我心想,我怎么记得应该是one呢,
好吧,你说怎么样就怎么样。于是把特殊情况挑出来,在最前面加上:
if node.key == one or node.key == two
return node.parent.key
end
然后把刚才加的等号去掉。这下面试官说I like that。
接下来问我对unix/linux熟悉不,我说我平常就是用Ubuntu在写程序,但我对shell编
程不熟。他问写简单的bash script呢,我说我会把几个命令放在一起,但如果要加上
if, loop等我就不熟了。他问如果让你写bash script,are u comfortable with that
,我说我可以学,I like Linux more than Windows。他说it's great to hear that.
(看来Twitter对unix/linux很看重啊,两次面试都被问到这个。)
然后就结束了,也没让我问问题。我看他是个build&release engineer,本来还想问他
关于Twitter怎么build&release。总共才花了30 min
z*****n
发帖数: 447
5
第二题看你的解法,应该是Find the first common parent in a BST吧
l****p
发帖数: 397
6
是的

【在 z*****n 的大作中提到】
: 第二题看你的解法,应该是Find the first common parent in a BST吧
g*****e
发帖数: 282
7
普通tree的话只能brute force把两个paths都先找出来了吧?

【在 z*****n 的大作中提到】
: 第二题看你的解法,应该是Find the first common parent in a BST吧
c********t
发帖数: 5706
8
since he could use "node.parent.key"
why not directly compare all parents of one and two?
how to find the path to a node in a binary tree?

【在 g*****e 的大作中提到】
: 普通tree的话只能brute force把两个paths都先找出来了吧?
g*****e
发帖数: 282
9
如果没有parent pointers,从root开始。这些应该开始做题前问清interviewer的~

【在 c********t 的大作中提到】
: since he could use "node.parent.key"
: why not directly compare all parents of one and two?
: how to find the path to a node in a binary tree?

g*****e
发帖数: 282
10
普通tree的话只能brute force把两个paths都先找出来了吧?

【在 z*****n 的大作中提到】
: 第二题看你的解法,应该是Find the first common parent in a BST吧
相关主题
MS面试题我想了想
今天面试惨败,分享面经BST合并的面试题
BST面试题一个GOOG的二叉树面试题
进入JobHunting版参与讨论
c********t
发帖数: 5706
11
since he could use "node.parent.key"
why not directly compare all parents of one and two?
how to find the path to a node in a binary tree?

【在 g*****e 的大作中提到】
: 普通tree的话只能brute force把两个paths都先找出来了吧?
g*****e
发帖数: 282
12
如果没有parent pointers,从root开始。这些应该开始做题前问清interviewer的~

【在 c********t 的大作中提到】
: since he could use "node.parent.key"
: why not directly compare all parents of one and two?
: how to find the path to a node in a binary tree?

l**b
发帖数: 457
13
Mark
h****n
发帖数: 1093
14
第二个tree的题,对方貌似没说是BST吧。。。
l****p
发帖数: 397
15
太久了,我不记得当时说的是tree还是BST了。不过这个确实需要特别向面试官clarify
的,因为有些算法仅适用于BST

【在 h****n 的大作中提到】
: 第二个tree的题,对方貌似没说是BST吧。。。
l****o
发帖数: 315
16
哇。好难得看到一个用ruby的。
1 (共1页)
进入JobHunting版参与讨论
相关主题
微软 intern offer求教一道老题
小公司web server面经MS面试题
sorted linked list里insert一个node今天面试惨败,分享面经
急!google 一面。请大侠看看BST面试题
Linkedin 电面面经,已跪,求分析是不是被黑。我想了想
感恩发面经-Amazon第二轮电面BST合并的面试题
A M onsite相继被拒 伤心之余附上面经和总结, 顺便求refer一个GOOG的二叉树面试题
snapchat以及FLG 面经(已挂)问一道旧题
相关话题的讨论汇总
话题: end话题: parent话题: two话题: ruby话题: 然后