由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Facebook Phone Inteview + 流程请教
相关主题
请教一下subset I 输出子集顺序问题求救, F家onsite算法题
请教一个题目请教一道面试题
请教leetcode Subsets IIpartition array problem
a problem from leetcode: high efficiency algorithm for combinations problem请教,Binary Tree Level Traversal有recursive的算法么?
combinations 有没有 iterative的方法阿 ?path sum II OJ 超时
Combination Sum II哪里做错了星期一福利:某公司店面题
常见编程面试题答案的2种格式,哪种最好?Tree的traversal也分BFS和DFS?
请问一个java的问题(leetcode subsets一题)Leetcode上subsets-ii的疑问
相关话题的讨论汇总
话题: int话题: arraylist话题: set话题: integer话题: index
进入JobHunting版参与讨论
1 (共1页)
d****j
发帖数: 293
1
面试官没提到题目不可以外泄,而且也都是常见的, 所以就在这里发了。
两轮电话面试都是45分钟,2道编程题,白板共享文档写程序。
简单寒暄5-10分钟,谈谈research,最近做的project等等。
然后直接告知共享文档link,写程序。
Round 1:
A. Given an arbitrary tree, can you print it level by level (with each level
printed on the same line).Define your own tree node structure, can be
binary tree or n-ary tree.
B. Given a set of distinct integers, can you print out all subsets?
Round 2:
A. Remove duplicated integers in an array, and then return an array without
duplicates. Follow up: what if allow duplicates at most twice?
i.e., [1, 1, 1, 2, 2, 3, 2] --> [1, 1, 2, 2, 3]
B. Given a string and a dictionary that maps a character to several
characters, print all combination and tell the complexity.
i.e., string = "face", f=> f, @, 4, h a=> a, c, e
print: face, @ace, 4ace, .....
大家再简单讨论一下,我再比较一下做的对不对。
都是很常见的问题,所以很快就program完了,结果还剩下不少时间。面试官就问有什么问题,我就简单问了3个左右,然后就完了。
现在Facebook还要来一次phone interview,说是最后一次了,晕死,本来就很紧张,还要来一轮,刺激死了。敢情是回答的太快,代码是抄的,我的理解了....
有谁知道facebook一般需要需要几轮电面啊?几轮on-site?
j********x
发帖数: 2330
2
题目这么简单,竟然不给我interview。。。
d******a
发帖数: 238
3
第一轮的第二题你怎么做的?看看你的程序。
第二轮的第一题用hash? 第二题就是电话键的变种吧。
c********n
发帖数: 26
4
楼主第二轮的B是怎么考虑的呢?
H****S
发帖数: 1359
5
import java.util.ArrayList;
public ArrayList> uniqueSet(int[] a, int i) {
ArrayList retList = new ArrayList>();
if (i < 0) {
retList.add(new ArrayList);
return retList;
}
for (ArrayList list : uniqueSet(a, i - 1)) {
retList.add((ArrayList)(list.clone())); //ugly
list.add(new Integer(a[i]));
retList.add((ArrayList)(list.clone())); //ugly
}
return retList;
}

【在 d******a 的大作中提到】
: 第一轮的第二题你怎么做的?看看你的程序。
: 第二轮的第一题用hash? 第二题就是电话键的变种吧。

d****j
发帖数: 293
6
第一轮第二题
电面之前刚好练过这道题,但是用ArrayList 和ArrayList of ArrayList 实现的,用
recrusive 的方法,返回前k个元素的幂集合之后,再复制一边添加当前k+1元素入每个
子集合。最终返回幂集之后在打印,效率不好。但是当时想都没想就写上去了。
面完了就想起,完全可以用一个等长的int数组来标识是否取当前元素,代码如下。(
Careercup有这道题,使用一个int数i的每一位来做标识,把i从0递增到2^32-1就能打
印出所有的subsets,但最多只能实现到32个数的数组)
public static void printPowerSet(int[] set) {
int[] index = new int[set.length];
int endidx = 0;
printPowerSetSolver(set, index, endidx);
}
public static void printPowerSetSolver(int[] set, int[] index, int endidx) {
if (endidx == set.length) {
printSet(set, index);
return;
}
index[endidx] = 0;
printPowerSetSolver(set, index, endidx + 1);
index[endidx] = 1;
printPowerSetSolver(set, index, endidx + 1);
}
public static void printSet(int[] set, int[] index) {
for (int i = 0; i < set.length; i++)
if (index[i] > 0)
System.out.print(set[i] + " ");
System.out.println();
}
第二轮
第一题是用的Hash
第二题是电话变种,我同样用recursive的方法,用endindex表示当前处理的位置,用
一个for loop来实现每个位置都能取遍所有的替代字符,然后就call itself。
d******a
发帖数: 238
7
这个解法很清楚,谢谢。我还想问的是,如果要在n个数中找出m个数的组合(比如4个
数中找2个数的组合),用这种解法的话,应该改第三个函数就可以了吧?统计index数
组中1的个数为m个时再打印?

【在 d****j 的大作中提到】
: 第一轮第二题
: 电面之前刚好练过这道题,但是用ArrayList 和ArrayList of ArrayList 实现的,用
: recrusive 的方法,返回前k个元素的幂集合之后,再复制一边添加当前k+1元素入每个
: 子集合。最终返回幂集之后在打印,效率不好。但是当时想都没想就写上去了。
: 面完了就想起,完全可以用一个等长的int数组来标识是否取当前元素,代码如下。(
: Careercup有这道题,使用一个int数i的每一位来做标识,把i从0递增到2^32-1就能打
: 印出所有的subsets,但最多只能实现到32个数的数组)
: public static void printPowerSet(int[] set) {
: int[] index = new int[set.length];
: int endidx = 0;

e***t
发帖数: 185
8
up
d**u
发帖数: 1065
9
第一轮第一题:BFS
第一轮第二题:DFS
第二轮第一题: 要看max输入有多大,小的话O(N),大的话O(NlogN),是我做的话,不用hash,直接改快排算法
第二轮第二题:DFS
v***n
发帖数: 562
10
请问哪里可以找到interview题库?谢谢!
相关主题
Combination Sum II哪里做错了求救, F家onsite算法题
常见编程面试题答案的2种格式,哪种最好?请教一道面试题
请问一个java的问题(leetcode subsets一题)partition array problem
进入JobHunting版参与讨论
d****j
发帖数: 293
11
Combination: 如果这样的话,有点大材小用了吧,一个是2^n的复杂度,另外一个是多
项式复杂度,只修改打印方程会浪费很多时间
我的想法,另外用一个数组value作参数存取被选中的数字,还是用recursive的方法,
用一个index来记录当前fill多少个数字了。
Base:如果达到了limit,直接打印value数组
Recursive: 当前需要fill的index可以选那些数字?用一个for loop实现,赋值给
value[index]一个可选的数字,然后call itself 来fill下一个位置。 由于是
combination,需要注意不能重复选以前的数字了,下一个位置永远是从之前选中的数
的后面数字里面选。所以,还需要一个参数来标注可选数字的起始点(原始数组中)。
这样的话,大概需要5个参数,2个数组,2个index,和选出数的limit。
我刚刚写了一下,这个思路code还是没问题的。注意边界条件和候选取值范围。
衍生的问题就是:Permutation
也是用类似的idea,但是比combination更简单,和powerset差不多,增加一个for loop
,recursive call 之后再reset当前的value。
多写几个recursive的问题以后,马上就能用到很多问题,改改迭代call之前或者之后
的赋值就能有很多变化。

【在 d******a 的大作中提到】
: 这个解法很清楚,谢谢。我还想问的是,如果要在n个数中找出m个数的组合(比如4个
: 数中找2个数的组合),用这种解法的话,应该改第三个函数就可以了吧?统计index数
: 组中1的个数为m个时再打印?

j*****u
发帖数: 1133
12
just wrote a non-recursive subset function in C#
static IList> GetSubsets(ISet set)
{
if (set == null)
throw new ArgumentNullException("set");
List> list = new List>();
var allElements = set.ToArray();
for (int i = 0; i < (1 << set.Count); ++i)
{
var subset = new HashSet();
int mask = i;
int index = 0;
while (mask > 0)
{
if ((mask & 0x1) != 0)
subset.Add(allElements[index]);
++index;
mask >>= 1;
}
list.Add(subset);
}

return list;
}

【在 d****j 的大作中提到】
: 第一轮第二题
: 电面之前刚好练过这道题,但是用ArrayList 和ArrayList of ArrayList 实现的,用
: recrusive 的方法,返回前k个元素的幂集合之后,再复制一边添加当前k+1元素入每个
: 子集合。最终返回幂集之后在打印,效率不好。但是当时想都没想就写上去了。
: 面完了就想起,完全可以用一个等长的int数组来标识是否取当前元素,代码如下。(
: Careercup有这道题,使用一个int数i的每一位来做标识,把i从0递增到2^32-1就能打
: 印出所有的subsets,但最多只能实现到32个数的数组)
: public static void printPowerSet(int[] set) {
: int[] index = new int[set.length];
: int endidx = 0;

l*****a
发帖数: 14598
13
1B就用PIE解法,不是很好吗?
也可以用下面说的字典解法(每步加一)
int不够的话就用个额外的数组,相对于时间复杂度
这个额外空间应该影响不大

【在 d****j 的大作中提到】
: 第一轮第二题
: 电面之前刚好练过这道题,但是用ArrayList 和ArrayList of ArrayList 实现的,用
: recrusive 的方法,返回前k个元素的幂集合之后,再复制一边添加当前k+1元素入每个
: 子集合。最终返回幂集之后在打印,效率不好。但是当时想都没想就写上去了。
: 面完了就想起,完全可以用一个等长的int数组来标识是否取当前元素,代码如下。(
: Careercup有这道题,使用一个int数i的每一位来做标识,把i从0递增到2^32-1就能打
: 印出所有的subsets,但最多只能实现到32个数的数组)
: public static void printPowerSet(int[] set) {
: int[] index = new int[set.length];
: int endidx = 0;

b**********n
发帖数: 399
14
2-3轮电面 1轮onsite

level

【在 d****j 的大作中提到】
: 面试官没提到题目不可以外泄,而且也都是常见的, 所以就在这里发了。
: 两轮电话面试都是45分钟,2道编程题,白板共享文档写程序。
: 简单寒暄5-10分钟,谈谈research,最近做的project等等。
: 然后直接告知共享文档link,写程序。
: Round 1:
: A. Given an arbitrary tree, can you print it level by level (with each level
: printed on the same line).Define your own tree node structure, can be
: binary tree or n-ary tree.
: B. Given a set of distinct integers, can you print out all subsets?
: Round 2:

d****j
发帖数: 293
15
面试官没提到题目不可以外泄,而且也都是常见的, 所以就在这里发了。
两轮电话面试都是45分钟,2道编程题,白板共享文档写程序。
简单寒暄5-10分钟,谈谈research,最近做的project等等。
然后直接告知共享文档link,写程序。
Round 1:
A. Given an arbitrary tree, can you print it level by level (with each level
printed on the same line).Define your own tree node structure, can be
binary tree or n-ary tree.
B. Given a set of distinct integers, can you print out all subsets?
Round 2:
A. Remove duplicated integers in an array, and then return an array without
duplicates. Follow up: what if allow duplicates at most twice?
i.e., [1, 1, 1, 2, 2, 3, 2] --> [1, 1, 2, 2, 3]
B. Given a string and a dictionary that maps a character to several
characters, print all combination and tell the complexity.
i.e., string = "face", f=> f, @, 4, h a=> a, c, e
print: face, @ace, 4ace, .....
大家再简单讨论一下,我再比较一下做的对不对。
都是很常见的问题,所以很快就program完了,结果还剩下不少时间。面试官就问有什么问题,我就简单问了3个左右,然后就完了。
现在Facebook还要来一次phone interview,说是最后一次了,晕死,本来就很紧张,还要来一轮,刺激死了。敢情是回答的太快,代码是抄的,我的理解了....
有谁知道facebook一般需要需要几轮电面啊?几轮on-site?
j********x
发帖数: 2330
16
题目这么简单,竟然不给我interview。。。
d******a
发帖数: 238
17
第一轮的第二题你怎么做的?看看你的程序。
第二轮的第一题用hash? 第二题就是电话键的变种吧。
c********n
发帖数: 26
18
楼主第二轮的B是怎么考虑的呢?
H****S
发帖数: 1359
19
import java.util.ArrayList;
public ArrayList> uniqueSet(int[] a, int i) {
ArrayList retList = new ArrayList>();
if (i < 0) {
retList.add(new ArrayList);
return retList;
}
for (ArrayList list : uniqueSet(a, i - 1)) {
retList.add((ArrayList)(list.clone())); //ugly
list.add(new Integer(a[i]));
retList.add((ArrayList)(list.clone())); //ugly
}
return retList;
}

【在 d******a 的大作中提到】
: 第一轮的第二题你怎么做的?看看你的程序。
: 第二轮的第一题用hash? 第二题就是电话键的变种吧。

d****j
发帖数: 293
20
第一轮第二题
电面之前刚好练过这道题,但是用ArrayList 和ArrayList of ArrayList 实现的,用
recrusive 的方法,返回前k个元素的幂集合之后,再复制一边添加当前k+1元素入每个
子集合。最终返回幂集之后在打印,效率不好。但是当时想都没想就写上去了。
面完了就想起,完全可以用一个等长的int数组来标识是否取当前元素,代码如下。(
Careercup有这道题,使用一个int数i的每一位来做标识,把i从0递增到2^32-1就能打
印出所有的subsets,但最多只能实现到32个数的数组)
public static void printPowerSet(int[] set) {
int[] index = new int[set.length];
int endidx = 0;
printPowerSetSolver(set, index, endidx);
}
public static void printPowerSetSolver(int[] set, int[] index, int endidx) {
if (endidx == set.length) {
printSet(set, index);
return;
}
index[endidx] = 0;
printPowerSetSolver(set, index, endidx + 1);
index[endidx] = 1;
printPowerSetSolver(set, index, endidx + 1);
}
public static void printSet(int[] set, int[] index) {
for (int i = 0; i < set.length; i++)
if (index[i] > 0)
System.out.print(set[i] + " ");
System.out.println();
}
第二轮
第一题是用的Hash
第二题是电话变种,我同样用recursive的方法,用endindex表示当前处理的位置,用
一个for loop来实现每个位置都能取遍所有的替代字符,然后就call itself。
相关主题
请教,Binary Tree Level Traversal有recursive的算法么?Tree的traversal也分BFS和DFS?
path sum II OJ 超时Leetcode上subsets-ii的疑问
星期一福利:某公司店面题请教一道面试题
进入JobHunting版参与讨论
d******a
发帖数: 238
21
这个解法很清楚,谢谢。我还想问的是,如果要在n个数中找出m个数的组合(比如4个
数中找2个数的组合),用这种解法的话,应该改第三个函数就可以了吧?统计index数
组中1的个数为m个时再打印?

【在 d****j 的大作中提到】
: 第一轮第二题
: 电面之前刚好练过这道题,但是用ArrayList 和ArrayList of ArrayList 实现的,用
: recrusive 的方法,返回前k个元素的幂集合之后,再复制一边添加当前k+1元素入每个
: 子集合。最终返回幂集之后在打印,效率不好。但是当时想都没想就写上去了。
: 面完了就想起,完全可以用一个等长的int数组来标识是否取当前元素,代码如下。(
: Careercup有这道题,使用一个int数i的每一位来做标识,把i从0递增到2^32-1就能打
: 印出所有的subsets,但最多只能实现到32个数的数组)
: public static void printPowerSet(int[] set) {
: int[] index = new int[set.length];
: int endidx = 0;

d**u
发帖数: 1065
22
第一轮第一题:BFS
第一轮第二题:DFS
第二轮第一题: 要看max输入有多大,小的话O(N),大的话O(NlogN),是我做的话,不用hash,直接改快排算法
第二轮第二题:DFS
v***n
发帖数: 562
23
请问哪里可以找到interview题库?谢谢!
d****j
发帖数: 293
24
Combination: 如果这样的话,有点大材小用了吧,一个是2^n的复杂度,另外一个是多
项式复杂度,只修改打印方程会浪费很多时间
我的想法,另外用一个数组value作参数存取被选中的数字,还是用recursive的方法,
用一个index来记录当前fill多少个数字了。
Base:如果达到了limit,直接打印value数组
Recursive: 当前需要fill的index可以选那些数字?用一个for loop实现,赋值给
value[index]一个可选的数字,然后call itself 来fill下一个位置。 由于是
combination,需要注意不能重复选以前的数字了,下一个位置永远是从之前选中的数
的后面数字里面选。所以,还需要一个参数来标注可选数字的起始点(原始数组中)。
这样的话,大概需要5个参数,2个数组,2个index,和选出数的limit。
我刚刚写了一下,这个思路code还是没问题的。注意边界条件和候选取值范围。
衍生的问题就是:Permutation
也是用类似的idea,但是比combination更简单,和powerset差不多,增加一个for loop
,recursive call 之后再reset当前的value。
多写几个recursive的问题以后,马上就能用到很多问题,改改迭代call之前或者之后
的赋值就能有很多变化。

【在 d******a 的大作中提到】
: 这个解法很清楚,谢谢。我还想问的是,如果要在n个数中找出m个数的组合(比如4个
: 数中找2个数的组合),用这种解法的话,应该改第三个函数就可以了吧?统计index数
: 组中1的个数为m个时再打印?

j*****u
发帖数: 1133
25
just wrote a non-recursive subset function in C#
static IList> GetSubsets(ISet set)
{
if (set == null)
throw new ArgumentNullException("set");
List> list = new List>();
var allElements = set.ToArray();
for (int i = 0; i < (1 << set.Count); ++i)
{
var subset = new HashSet();
int mask = i;
int index = 0;
while (mask > 0)
{
if ((mask & 0x1) != 0)
subset.Add(allElements[index]);
++index;
mask >>= 1;
}
list.Add(subset);
}

return list;
}

【在 d****j 的大作中提到】
: 第一轮第二题
: 电面之前刚好练过这道题,但是用ArrayList 和ArrayList of ArrayList 实现的,用
: recrusive 的方法,返回前k个元素的幂集合之后,再复制一边添加当前k+1元素入每个
: 子集合。最终返回幂集之后在打印,效率不好。但是当时想都没想就写上去了。
: 面完了就想起,完全可以用一个等长的int数组来标识是否取当前元素,代码如下。(
: Careercup有这道题,使用一个int数i的每一位来做标识,把i从0递增到2^32-1就能打
: 印出所有的subsets,但最多只能实现到32个数的数组)
: public static void printPowerSet(int[] set) {
: int[] index = new int[set.length];
: int endidx = 0;

l*****a
发帖数: 14598
26
1B就用PIE解法,不是很好吗?
也可以用下面说的字典解法(每步加一)
int不够的话就用个额外的数组,相对于时间复杂度
这个额外空间应该影响不大

【在 d****j 的大作中提到】
: 第一轮第二题
: 电面之前刚好练过这道题,但是用ArrayList 和ArrayList of ArrayList 实现的,用
: recrusive 的方法,返回前k个元素的幂集合之后,再复制一边添加当前k+1元素入每个
: 子集合。最终返回幂集之后在打印,效率不好。但是当时想都没想就写上去了。
: 面完了就想起,完全可以用一个等长的int数组来标识是否取当前元素,代码如下。(
: Careercup有这道题,使用一个int数i的每一位来做标识,把i从0递增到2^32-1就能打
: 印出所有的subsets,但最多只能实现到32个数的数组)
: public static void printPowerSet(int[] set) {
: int[] index = new int[set.length];
: int endidx = 0;

b**********n
发帖数: 399
27
2-3轮电面 1轮onsite

level

【在 d****j 的大作中提到】
: 面试官没提到题目不可以外泄,而且也都是常见的, 所以就在这里发了。
: 两轮电话面试都是45分钟,2道编程题,白板共享文档写程序。
: 简单寒暄5-10分钟,谈谈research,最近做的project等等。
: 然后直接告知共享文档link,写程序。
: Round 1:
: A. Given an arbitrary tree, can you print it level by level (with each level
: printed on the same line).Define your own tree node structure, can be
: binary tree or n-ary tree.
: B. Given a set of distinct integers, can you print out all subsets?
: Round 2:

s*******f
发帖数: 1114
28
//A. Given an arbitrary tree, can you print it level by level (with each
level
//printed on the same line).Define your own tree node structure, can be
//binary tree or n-ary tree.
struct Node{
int d;
std::vector children;
};
void PrintByLevel(Node *r){
if (!r)
return;
std::queue q;
q.push(r);
int pre_count = 1;
int count = 0;
while (!q.empty()){
Node *p = q.front();
for (std::vector::const_iterator ci = p-
>children.begin(); ci != p->children.end(); ++ci){
q.push(*ci);
++count;
}
printf("%d ", p->d);
--pre_count;
if (pre_count < 1){
printf("\n");
pre_count = count;
count = 0;
}
}
}
//B. Given a set of distinct integers, can you print out all subsets?
void PrintAllSubsets(int in[], int len){
static std::vector v;
if (len < 1){
for (std::vector::const_iterator ci = v.begin(); ci !=
v.end(); ++ci){
printf("%d ", *ci);
}
printf("\n");
return;
}
v.push_back(in[0]);
PrintAllSubsets(in + 1, len - 1);
v.pop_back();
PrintAllSubsets(in + 1, len - 1);
}
//Round 2:
//A. Remove duplicated integers in an array, and then return an array
without
//duplicates. Follow up: what if allow duplicates at most twice?
//i.e., [1, 1, 1, 2, 2, 3, 2] --> [1, 1, 2, 2, 3]
// return new length.
int RemoveDuplicatedRemainAtMostTwice(int in[], int len){
if (!in || len < 2)
return len;
std::sort(in, in + len);
int i = 0;
int j = 1;
bool has_two = false;
int length = len;
while (j < len){
if (in[i] == in[j]){
if (has_two){
++j;
--length;
}else{
in[++i] = in[j++];
has_two = true;
}
}else{
has_two = false;
in[++i] = in[j++];
}
}
return length;
}
//B. Given a string and a dictionary that maps a character to several
//characters, print all combination and tell the complexity.
//i.e., string = "face", f=> f, @, 4, h a=> a, c, e
//print: face, @ace, 4ace, .....
void PrintAllCombination(char *str, std::map< char, std::vector > &m){
static std::vector v;
if (!*str){
for (std::vector::const_iterator ci = v.begin(); ci !=
v.end(); ++ci){
printf("%c", *ci);
}
printf("\n");
return;
}
if (m.find(*str) == m.end()){
v.push_back(*str);
PrintAllCombination(str + 1, m);
v.pop_back();
}else{
for (std::vector::iterator ci = m[*str].begin(); ci !=
m[*str].end(); ++ci){
v.push_back(*ci);
PrintAllCombination(str + 1, m);
v.pop_back();
}
}
}
i******w
发帖数: 214
29
不够用就加integer

【在 d****j 的大作中提到】
: 第一轮第二题
: 电面之前刚好练过这道题,但是用ArrayList 和ArrayList of ArrayList 实现的,用
: recrusive 的方法,返回前k个元素的幂集合之后,再复制一边添加当前k+1元素入每个
: 子集合。最终返回幂集之后在打印,效率不好。但是当时想都没想就写上去了。
: 面完了就想起,完全可以用一个等长的int数组来标识是否取当前元素,代码如下。(
: Careercup有这道题,使用一个int数i的每一位来做标识,把i从0递增到2^32-1就能打
: 印出所有的subsets,但最多只能实现到32个数的数组)
: public static void printPowerSet(int[] set) {
: int[] index = new int[set.length];
: int endidx = 0;

h******3
发帖数: 351
30
How do you get the opportunity? Are you from tier one school (if you dont
mind)?

level

【在 d****j 的大作中提到】
: 面试官没提到题目不可以外泄,而且也都是常见的, 所以就在这里发了。
: 两轮电话面试都是45分钟,2道编程题,白板共享文档写程序。
: 简单寒暄5-10分钟,谈谈research,最近做的project等等。
: 然后直接告知共享文档link,写程序。
: Round 1:
: A. Given an arbitrary tree, can you print it level by level (with each level
: printed on the same line).Define your own tree node structure, can be
: binary tree or n-ary tree.
: B. Given a set of distinct integers, can you print out all subsets?
: Round 2:

相关主题
问道leetcode的题:Combination Sum II请教一个题目
求教一下,我的这个代码有什么问题请教leetcode Subsets II
请教一下subset I 输出子集顺序问题a problem from leetcode: high efficiency algorithm for combinations problem
进入JobHunting版参与讨论
r*******g
发帖数: 1335
31
没有想象中难,我还以为facebook的面试题和那些puzzle一样呢。
r*******g
发帖数: 1335
32
没有想象中难,我还以为facebook的面试题和那些puzzle一样呢。
y*******g
发帖数: 6599
33
汗颜,我觉得这些要电面写出干净code还是有点难度的

【在 r*******g 的大作中提到】
: 没有想象中难,我还以为facebook的面试题和那些puzzle一样呢。
t*****n
发帖数: 25
34
太牛了。第一题要pop 吧。

【在 s*******f 的大作中提到】
: //A. Given an arbitrary tree, can you print it level by level (with each
: level
: //printed on the same line).Define your own tree node structure, can be
: //binary tree or n-ary tree.
: struct Node{
: int d;
: std::vector children;
: };
: void PrintByLevel(Node *r){
: if (!r)

s*******f
发帖数: 1114
35
这都被你看得出来!那queue都快被我塞爆了。

【在 t*****n 的大作中提到】
: 太牛了。第一题要pop 吧。
s*****n
发帖数: 994
36
第二轮第一题hash怎么写?用c或者c++ coding时候没有hash啊,难道用map?

level

【在 d****j 的大作中提到】
: 面试官没提到题目不可以外泄,而且也都是常见的, 所以就在这里发了。
: 两轮电话面试都是45分钟,2道编程题,白板共享文档写程序。
: 简单寒暄5-10分钟,谈谈research,最近做的project等等。
: 然后直接告知共享文档link,写程序。
: Round 1:
: A. Given an arbitrary tree, can you print it level by level (with each level
: printed on the same line).Define your own tree node structure, can be
: binary tree or n-ary tree.
: B. Given a set of distinct integers, can you print out all subsets?
: Round 2:

s*****n
发帖数: 994
37
round 1/A:
void printTree (node * root){
if (!root) return;
node* pointer;
stack*> astack;
astack.push(root);
while (!astack.empty()){
pointer=astack.top();
if (!pointer) continue;
print(pointer);
astack.pop();
astack.push(point->left());
astack.push(point->right());
}
}

level

【在 d****j 的大作中提到】
: 面试官没提到题目不可以外泄,而且也都是常见的, 所以就在这里发了。
: 两轮电话面试都是45分钟,2道编程题,白板共享文档写程序。
: 简单寒暄5-10分钟,谈谈research,最近做的project等等。
: 然后直接告知共享文档link,写程序。
: Round 1:
: A. Given an arbitrary tree, can you print it level by level (with each level
: printed on the same line).Define your own tree node structure, can be
: binary tree or n-ary tree.
: B. Given a set of distinct integers, can you print out all subsets?
: Round 2:

s*****n
发帖数: 994
38
void printAllSubSet(int set[], int size){
if (size<=0) return;
int reviewed = new int [size];
int lreviewed = 0;
printAllSub (reviewed, lreviewed, set, size);
}
void printAllSub (int reviewed[], int lreviewed, int set[], int size){
if (lreviewed==size){
for (int i=0;i if (reviewed[i]) print(set[i]);
}
}
lreviewed += 1;
printAllSub (reviewd, lreviewed, set, size);
reviewed[lreviewed-1] = 1;
printAllSub (reviewd, lreviewed, set, size);
}

level

【在 d****j 的大作中提到】
: 面试官没提到题目不可以外泄,而且也都是常见的, 所以就在这里发了。
: 两轮电话面试都是45分钟,2道编程题,白板共享文档写程序。
: 简单寒暄5-10分钟,谈谈research,最近做的project等等。
: 然后直接告知共享文档link,写程序。
: Round 1:
: A. Given an arbitrary tree, can you print it level by level (with each level
: printed on the same line).Define your own tree node structure, can be
: binary tree or n-ary tree.
: B. Given a set of distinct integers, can you print out all subsets?
: Round 2:

s*****n
发帖数: 994
39
round 2/A
int removeDupMoreThanTwo (int set[], int size){
std::map amap;
int write=0,;
for (int i=0; i if (amap.find(set[i])==amap.end()) {amap.insert(pair(set[i],1))
; set[write]=set[i]; write++}
else if (amap[set[i]]->second()<=2) {amap[set[i]]++;set[write]=set[i];
write++}
else amap[set[i]]++;
}
return write+1;
}

level

【在 d****j 的大作中提到】
: 面试官没提到题目不可以外泄,而且也都是常见的, 所以就在这里发了。
: 两轮电话面试都是45分钟,2道编程题,白板共享文档写程序。
: 简单寒暄5-10分钟,谈谈research,最近做的project等等。
: 然后直接告知共享文档link,写程序。
: Round 1:
: A. Given an arbitrary tree, can you print it level by level (with each level
: printed on the same line).Define your own tree node structure, can be
: binary tree or n-ary tree.
: B. Given a set of distinct integers, can you print out all subsets?
: Round 2:

s*****n
发帖数: 994
40
round 2/B, same with round 1/B, except use a for loop to change the current
bit

level

【在 d****j 的大作中提到】
: 面试官没提到题目不可以外泄,而且也都是常见的, 所以就在这里发了。
: 两轮电话面试都是45分钟,2道编程题,白板共享文档写程序。
: 简单寒暄5-10分钟,谈谈research,最近做的project等等。
: 然后直接告知共享文档link,写程序。
: Round 1:
: A. Given an arbitrary tree, can you print it level by level (with each level
: printed on the same line).Define your own tree node structure, can be
: binary tree or n-ary tree.
: B. Given a set of distinct integers, can you print out all subsets?
: Round 2:

相关主题
a problem from leetcode: high efficiency algorithm for combinations problem常见编程面试题答案的2种格式,哪种最好?
combinations 有没有 iterative的方法阿 ?请问一个java的问题(leetcode subsets一题)
Combination Sum II哪里做错了求救, F家onsite算法题
进入JobHunting版参与讨论
l****s
发帖数: 165
41
Facebook interviews:
http://myguiding.com/viewforum.php?f=98

level

【在 d****j 的大作中提到】
: 面试官没提到题目不可以外泄,而且也都是常见的, 所以就在这里发了。
: 两轮电话面试都是45分钟,2道编程题,白板共享文档写程序。
: 简单寒暄5-10分钟,谈谈research,最近做的project等等。
: 然后直接告知共享文档link,写程序。
: Round 1:
: A. Given an arbitrary tree, can you print it level by level (with each level
: printed on the same line).Define your own tree node structure, can be
: binary tree or n-ary tree.
: B. Given a set of distinct integers, can you print out all subsets?
: Round 2:

b*****c
发帖数: 1103
42
onsite之前是两轮 interview,你过了第一轮就不错了,我下周也要面fb,ms啦
r*******g
发帖数: 1335
43
那自然,我是以为facebook的难度都是看到题找不到入手点的,比如那些puzzle。
facebook实在太拽乐,貌似很难拿到interview机会。

【在 y*******g 的大作中提到】
: 汗颜,我觉得这些要电面写出干净code还是有点难度的
l******n
发帖数: 1250
44
请问楼主是new grad PhD 吗?
r***x
发帖数: 65
45
这个round 2B的做法是啥。。。
复杂度应该是每个位置可能出现数目的累乘?
s********l
发帖数: 998
46
round 2 B 就是用backtracking把~
e********u
发帖数: 587
47
这坟挖的...
J*******o
发帖数: 741
48
为什么是挖坟啊?。。。
1 (共1页)
进入JobHunting版参与讨论
相关主题
Leetcode上subsets-ii的疑问combinations 有没有 iterative的方法阿 ?
请教一道面试题Combination Sum II哪里做错了
问道leetcode的题:Combination Sum II常见编程面试题答案的2种格式,哪种最好?
求教一下,我的这个代码有什么问题请问一个java的问题(leetcode subsets一题)
请教一下subset I 输出子集顺序问题求救, F家onsite算法题
请教一个题目请教一道面试题
请教leetcode Subsets IIpartition array problem
a problem from leetcode: high efficiency algorithm for combinations problem请教,Binary Tree Level Traversal有recursive的算法么?
相关话题的讨论汇总
话题: int话题: arraylist话题: set话题: integer话题: index