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

02/09 F家onsite面经

🔗
 楼主| NR21 2016-2-23 23:57:38 | 只看该作者
全局:
queeniejing 发表于 2016-2-23 05:48
LZ onsite 只有三轮吗?

是的,貌似new grad都是三轮。
回复

使用道具 举报

🔗
新垣瞳澈 2016-2-24 01:47:28 | 只看该作者
全局:
LZ是哪天面的啊?已经出结果了?谢谢
回复

使用道具 举报

🔗
 楼主| NR21 2016-2-24 02:10:02 | 只看该作者
全局:
新垣瞳澈 发表于 2016-2-24 01:47
LZ是哪天面的啊?已经出结果了?谢谢

我是2月9号面的,一周出的结果
回复

使用道具 举报

🔗
Wrath 2016-4-18 04:06:40 | 只看该作者
全局:
LZ请问第二面的第二题应该怎么做比较好?
回复

使用道具 举报

🔗
jiebour 2016-4-18 05:40:04 | 只看该作者
全局:
楼主new grad?感觉题目简单啊。。。。另外楼主面之前有没有收到prep metairial 的pdf?比如告诉你会问哪些东西,algorithm,data structure,design pattern?有提到system design嘛?
回复

使用道具 举报

🔗
sealove999 2016-4-18 15:51:54 | 只看该作者
全局:
一面
  1. public class Solution {
  2.   public int minsteps(int board[][], int starti, int startj, int endi, int endj) {
  3.     int dirs[][] = new int[][] {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
  4.     int m = board.length;
  5.     int n = board[0].length;

  6.     boolean visited[][] = new boolean[m][n];
  7.     Deque<int[]> queue = new ArrayDeque<>(); // bfs

  8.     queue.offer(new int[] {starti, startj});
  9.     visited[starti][startj] = true;

  10.     int level = 0;
  11.     while (!queue.isEmpty()) {
  12.       level++;
  13.       int count = queue.size();
  14.       for (int i = 0; i < count; i++) {
  15.         int[] node = queue.poll();
  16.         for (int[] dir : dirs) {
  17.           int x = node[0] + dir[0];
  18.           int y = node[1] + dir[1];
  19.           if (x >= 0 && x < m && y >= 0 && y < n && board[x][y] != 1 && !visited[x][y]) {
  20.             if (x == endi && y == endj) {
  21.               return level;
  22.             }
  23.             queue.offer(new int[] {x, y});
  24.             visited[x][y] = true;
  25.           }
  26.         }
  27.       }
  28.     }
  29.     return -1;
  30.   }

  31.   public List<int[]> minpath(int board[][], int starti, int startj, int endi, int endj) {
  32.     int dirs[][] = new int[][] {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
  33.     int m = board.length;
  34.     int n = board[0].length;

  35.     Map<Integer, Integer> parent = new HashMap<>(); // int[] cannot equals
  36.     boolean visited[][] = new boolean[m][n];
  37.     Deque<int[]> queue = new ArrayDeque<>(); // bfs

  38.     queue.offer(new int[] {starti, startj});
  39.     visited[starti][startj] = true;

  40.     while (!queue.isEmpty()) {
  41.       int count = queue.size();
  42.       for (int i = 0; i < count; i++) {
  43.         int[] node = queue.poll();
  44.         for (int[] dir : dirs) {
  45.           int x = node[0] + dir[0];
  46.           int y = node[1] + dir[1];
  47.           if (x >= 0 && x < m && y >= 0 && y < n && board[x][y] != 1 && !visited[x][y]) {
  48.             queue.offer(new int[] {x, y});
  49.             visited[x][y] = true;
  50.             parent.put(x * n + y, node[0] * n + node[1]);
  51.             if (x == endi && y == endj) {
  52.               LinkedList<int[]> ret = new LinkedList<>();
  53.               while (x * n + y != starti * n + startj) {
  54.                 ret.offerFirst(new int[] {x, y});
  55.                 int p = parent.get(x * n + y);
  56.                 x = p / n;
  57.                 y = p % n;
  58.               }
  59.               return ret;
  60.             }
  61.           }
  62.         }
  63.       }
  64.     }
  65.     return null;
  66.   }

  67.   public static void main(String[] args) {
  68.     Solution s = new Solution();
  69.     System.out.println(s.minsteps(new int[][] {{0, 0, 0}, {0, 1, 0}, {0, 0, 0}}, 0, 1, 1, 1));
  70.     System.out.println(s.minsteps(new int[][] {{0, 0, 0}, {0, 1, 0}, {0, 0, 0}}, 0, 1, 2, 1));
  71.     System.out.println(s.minsteps(new int[][] {{0, 0, 0}, {0, 1, 0}, {0, 0, 0}}, 0, 1, 2, 2));
  72.     System.out.println();

  73.     System.out.println(s.minpath(new int[][] {{0, 0, 0}, {0, 1, 0}, {0, 0, 0}}, 0, 1, 1, 1));
  74.     for (int[] t : s.minpath(new int[][] {{0, 0, 0}, {0, 1, 0}, {0, 0, 0}}, 0, 1, 2, 1))
  75.       System.out.print("(" + t[0] + "," + t[1] + ") ");
  76.     System.out.println();
  77.     for (int[] t : s.minpath(new int[][] {{0, 0, 0}, {0, 1, 0}, {0, 0, 0}}, 0, 1, 2, 2))
  78.       System.out.print("(" + t[0] + "," + t[1] + ") ");
  79.     System.out.println();
  80.   }
  81. }
复制代码

补充内容 (2016-4-18 15:55):
二面,
    int dirs[][] = // 马走日
        new int[][] {{1, 2}, {-1, 2}, {1, -2}, {-1, -2}, {2, 1}, {-2, 1}, {2, -1}, {-2, -1}};
回复

使用道具 举报

🔗
sealove999 2016-4-18 16:06:20 | 只看该作者
全局:
三面
  1. public class Solution {
  2.   boolean issametree(TreeNode root1, TreeNode root2) {
  3.     if (root1 == null && root2 == null)
  4.       return true;
  5.     if (root1 != null && root2 != null) {
  6.       return root1.val == root2.val && issametree(root1.left, root2.left)
  7.           && issametree(root1.right, root2.right);
  8.     }
  9.     return false;
  10.   }

  11.   public boolean issubtree(TreeNode big, TreeNode small) {
  12.     if (big != null && small != null) {
  13.       if (big.val == small.val) {
  14.         if (issametree(big, small))
  15.           return true;
  16.       } else {
  17.         if (big.left != null && issubtree(big.left, small)) {
  18.           return true;
  19.         }
  20.         if (big.right != null && issubtree(big.right, small)) {
  21.           return true;
  22.         }
  23.       }
  24.     }
  25.     return false;
  26.   }


  27.   public static void main(String[] args) {
  28.     Solution s = new Solution();
  29.     TreeNode tn1 = new TreeNode(1);
  30.     TreeNode tn2 = new TreeNode(2);
  31.     TreeNode tn3 = new TreeNode(3);
  32.     TreeNode tn4 = new TreeNode(4);
  33.     TreeNode tn5 = new TreeNode(5);
  34.     tn1.left = tn2;
  35.     tn1.right = tn3;
  36.     tn4.left = tn5;
  37.     System.out.println(s.issubtree(tn1, tn2));
  38.     System.out.println(s.issubtree(tn1, tn4));
  39.   }
  40. }
复制代码
回复

使用道具 举报

🔗
Wrath 2016-4-21 06:26:15 | 只看该作者
全局:

如果只是把directions换成日字形走法的话万一中间走过的点有1怎么办,那样就不能走到那个点了。而且还得考虑[-1, 0]这种横向走一步,纵向来回走两步的情况,那样directions矩阵就有很多情况了。
回复

使用道具 举报

🔗
sealove999 2016-4-23 07:31:08 | 只看该作者
全局:
Wrath 发表于 2016-4-21 06:26
如果只是把directions换成日字形走法的话万一中间走过的点有1怎么办,那样就不能走到那个点了。而且还得 ...

噢噢噢噢是喔是喔
回复

使用道具 举报

🔗
zzx04025 2016-4-24 18:27:02 | 只看该作者
全局:
请问LZ第一题可以用DP做么,为什么我第一反应是DP呢……
回复

使用道具 举报

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

本版积分规则

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