回复: 27
跳转到指定楼层
上一主题 下一主题
收起左侧

Facebook Phone Interview

全局:

2014(10-12月) 码农类General 硕士 全职@meta - 内推 - 技术电面  | | Other |

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
(招工季节从7-9月到了10-12月)

一小时前FB电话面试,扯了20分钟简历才说:想要写点代码吗? 。。。

Iterator for in-order traversal of binary tree.  开始以为是iterative traverse in-order binary tree...还暗喜了一会。。
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
3px">很久都没有理解题目,,后面边理解边写边改的。写完面试官说有个Bug,我找了半天说没找到,给个提示。。还好他说是他看错了。。


求Onsite!!! 邮箱里面已经塞满了拒信。

评分

参与人数 3大米 +43 收起 理由
北美农民 + 30
Arthur2012 + 3 Fight on!
1guangnian + 10 感谢分享!

查看全部评分


上一篇:Goldman Sachs On Campus Interview
下一篇:qualcomm onsite interview
推荐
Neal_kks 2014-11-23 16:36:04 | 只看该作者
全局:
我用c++实现了一个,大家看看有么有bug吧。。
  1. #include <iostream>
  2. #include <stack>
  3. using namespace std;

  4. struct Tree{
  5.     int val;
  6.     Tree *left, *right;
  7.     Tree(int mval):val(mval), left(NULL), right(NULL){}
  8. };

  9. class TreeIterator{
  10. public:
  11.     TreeIterator(Tree *root){
  12.         flag = true;
  13.         if(root == NULL){
  14.             cur = NULL;
  15.             cout<<"invalid root point"<<endl;
  16.         }else{
  17.             while(root){
  18.                 st.push(root);
  19.                 root = root->left;
  20.             }
  21.             cur = st.top();
  22.         }
  23.     }
  24.     int value(){
  25.         if(cur == NULL){
  26.             cout<<"invalid operation"<<endl;
  27.             return -1;
  28.         }else{
  29.             cout<<cur->val<<endl;
  30.             return cur->val;
  31.         }
  32.     }
  33.     void next(){
  34.         if(cur == NULL){
  35.             cout<<"No next point"<<endl;
  36.             return;
  37.         }else{
  38.             if(cur->right){
  39.                 st.pop();
  40.                 cur = cur->right;
  41.                 st.push(cur);
  42.                 while(cur->left){
  43.                     cur = cur->left;
  44.                     st.push(cur);
  45.                 }
  46.             }else{
  47.                 st.pop();
  48.                 cur = st.empty()?NULL:st.top();
  49.             }
  50.         }
  51.     }
  52.     bool hasNext(){
  53.         return cur != NULL;
  54.     }
  55. private:
  56.     stack<Tree* > st;
  57.     Tree* cur;
  58.     bool flag;
  59. };

  60. int main(){
  61.     Tree *t1 = new Tree(1);
  62.     Tree *t2 = new Tree(2);
  63.     Tree *t3 = new Tree(3);
  64.     Tree *t4 = new Tree(4);
  65.     Tree *t5 = new Tree(5);
  66.     Tree *t6 = new Tree(6);
  67.     Tree *t7 = new Tree(7);
  68.     t1->left = t2, t1->right = t3;
  69.     t2->left = t4, t2->right = t5;
  70.     t3->left = t6, t3->right = t7;
  71.     TreeIterator tit(t1);
  72.     while(tit.hasNext()){
  73.         tit.value();
  74.         tit.next();
  75.     }
  76. }

  77. /*
  78.                 1
  79.                /\
  80.               2 3
  81.              /\ /\
  82.             4 56 7
  83.             */
复制代码
回复

使用道具 举报

全局:
  1. import java.util.Stack;
  2. public class IteratorOfInOrder {       
  3.         private TreeNode curr;
  4.         private Stack<TreeNode> nodes = new Stack<TreeNode>();       
  5.        
  6.         public IteratorOfInOrder(TreeNode root){
  7.                 TreeNode nd = root;
  8.                 while(nd != null){
  9.                         nodes.push(nd);
  10.                         nd = nd.left;
  11.                 }               
  12.         }
  13.        
  14.         public int value(){                       
  15.                 return curr.val;               
  16.         }

  17.         public void next(){
  18.                 if(!nodes.isEmpty()){
  19.                         curr = nodes.pop();                       
  20.                 }else{
  21.                         curr = null;
  22.                 }
  23.                
  24.                 if(curr != null) {
  25.                         TreeNode nd = curr;
  26.                         if(nd.right != null) {
  27.                                 nd = nd.right;
  28.                                 while(nd != null) {
  29.                                         nodes.push(nd);
  30.                                         nd = nd.left;
  31.                                 }
  32.                         }                       
  33.                 }
  34.         }
  35.        
  36.         public boolean hasNext(){
  37.                 return !nodes.isEmpty();
  38.         }
  39. }
复制代码
回复

使用道具 举报

全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
rettyye3 2014-11-8 08:24:46 | 只看该作者
全局:
这题用iterative version 的 inorder? 可以自己开个stack吗 还是说用morris?
回复

使用道具 举报

🔗
 楼主| 22691482 2014-11-8 08:39:36 | 只看该作者
全局:
rettyye3 发表于 2014-11-8 08:24
这题用iterative version 的 inorder? 可以自己开个stack吗 还是说用morris?

实现那个类的方法。
回复

使用道具 举报

🔗
rettyye3 2014-11-8 08:57:33 | 只看该作者
全局:
22691482 发表于 2014-11-8 08:39
实现那个类的方法。

哦, 我的意思是能不能自己给这个class加个private的stack, 或者这Node的结构有没有parent?

祝早日拿到onsite!
回复

使用道具 举报

无效楼层,该帖已经被删除
🔗
hno3 2014-11-8 10:01:11 | 只看该作者
全局:
楼主怎么做的啊,没想明白。。。
回复

使用道具 举报

🔗
 楼主| 22691482 2014-11-8 10:38:42 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

无效楼层,该帖已经被删除
🔗
 楼主| 22691482 2014-11-8 10:41:10 | 只看该作者
全局:
hno3 发表于 2014-11-8 10:01
楼主怎么做的啊,没想明白。。。

可以参考: CC150 4.5

构造函数那里就是把根传进去,然后跑到最左边。 (即in-order的第一个要遍历的元素)

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表