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

Qumulo phone interview failed (tad verbose)

全局:

2016(1-3月) 码农类General 硕士 全职@qumulo - 网上海投 - 技术电面  | | Fail | 应届毕业生

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

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

x
昨天电话面试了Qumulo,phone + collabedit.com。题目是一道算法题,和 相同。不同之处是矩阵中包含了fire和j
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
was tad verbose.” 唉还得练练啊。
  1. // Today, we’re going to be helping Joe. Joe works in a maze.
  2. // Unfortunately, portions of the maze have caught on fire, and
  3. // Joe doesn’t have the maze escape manual in his back pocket.
  4. //
  5. // Poor Joe! But you can help Joe escape the maze.
  6. //
  7. // Given a maze with both Joe and the squares that are on fire, you
  8. // must determine whether Joe can exit the maze before the fire
  9. // reaches him, and how long it takes him to do it (in minutes).
  10. //
  11. // Joe and the fire each move one square per minute, vertically or
  12. // horizontally (not diagonally). The fire spreads in four directions
  13. // from each square that is on fire. Joe may exit the maze from any
  14. // square that borders the edge of the maze. Neither Joe nor the fire
  15. // may enter a square that is occupied by a wall.
  16. //
  17. // As an example, consider the maze below:
  18. //
  19. // #############   Legend: J = Joe, F = fire, # = wall, |_ = exit
  20. // # J         #   It will take Joe 14 minutes to exit this maze.
  21. // ####  ##### #   The fire will be right behind him.
  22. // |  #  #   # #
  23. // |  #F #   # #
  24. // |__#______#_|
  25. //
  26. // The maze is represented by the data structure below. I’ve written
  27. // it in Java, but you can use whatever language you’re most
  28. // proficient in to solve the problem.

  29. public enum Square { Open, Wall, Fire, Joe };
  30. public class Maze {
  31. //Square[][] cells;
  32. vector<vector<Square> > cells;
  33. };

  34. public static int escapeTheMaze(Maze maze) {
  35.     queue<Maze> maze_queue;
  36.     maze_queue.push(maze);
  37.     int time = 0;
  38.     while (! maze_queue.empty()) {
  39.         size_t size = maze_queue.size();
  40.         for (size_t i = 0; i < size; ++ i) {
  41.             Maze current = maze_queue.top();
  42.             maze_queue.pop();
  43.             size_t joe[2];
  44.             for (size_t j = 0; j < current.cells.size(); ++ j) {
  45.                 for (size_t k = 0; k < current.cells[j].size(); ++ k) {
  46.                     if (Joe  == current.cells[j][k]) {
  47.                         if (0 == j || j + 1 == current.cells.size() || 0 == k || k + 1 == current.cells[j].size()) {
  48.                             return time;
  49.                         }
  50.                         joe[0] = j;
  51.                         joe[1] = k;
  52.                         current.cells[j][k] = Open;
  53.                         break;
  54.                     }
  55.                 }
  56.             }
  57.             Maze new_maze(current);
  58.             for (size_t j = 0; j < current.cells.size(); ++ j) {
  59.                 for (size_t k = 0; k < current.cells[j].size(); ++ k) {
  60.                     if (Fire == current.cells[j][k]) {
  61.                         if (j > 0 && Wall != current.cells[j - 1][k]) {
  62.                             new_maze[j - 1][k] = Fire;
  63.                         }
  64.                         if (j + 1 < current.cells.size() && Wall != current.cells[j + 1][k]) {
  65.                             new_maze[j + 1][k] = Fire;
  66.                         }
  67.                         if (k > 0 && Wall != current.cells[j][k - 1]) {
  68.                             new_maze[j][k - 1] = Fire;
  69.                         }
  70.                         if (k + 1 < current.cells[j].size() && Wall != current.cells[j][k + 1]) {
  71.                             new_maze[j][k + 1] = Fire;
  72.                         }
  73.                     }
  74.                 }
  75.             }
  76.             current = new_maze;
  77.             if (joe[0] > 0 && Open == current.cells[joe[0] - 1][joe[1]]) {
  78.                 Maze temp(current);
  79.                 temp.cells[joe[0] - 1][joe[1]] = Joe;
  80.                 maze_queue.push(temp);
  81.             }
  82.             if (joe[0] + 1 < current.cells.size() && Open == current.cells[joe[0] + 1][joe[1]]) {
  83.                 Maze temp(current);
  84.                 temp.cells[joe[0] + 1][joe[1]] = Joe;
  85.                 maze_queue.push(temp);
  86.             }
  87.             if (joe[1] > 0 && Open == current.cells[joe[0]][joe[1] - 1]) {
  88.                 Maze temp(current);
  89.                 temp.cells[joe[0]][joe[1] - 1] = Joe;
  90.                 maze_queue.push(temp);
  91.             }
  92.             if (joe[1] + 1 < current.cells[joe[0]].size() && Open == current.cells[joe[0]][joe[1] + 1]) {
  93.                 Maze temp(current);
  94.                 temp.cells[joe[0]][joe[1] + 1] = Joe;
  95.                 maze_queue.push(temp);
  96.             }
  97.         }
  98.         ++ time;
  99.     }
  100.     return -1;
  101. }
复制代码

评分

参与人数 2大米 +25 收起 理由
leoz0610 + 5 很有用的信息!
love1point + 20

查看全部评分


上一篇:请问Indeed Onsite (Austin)是2人share一个hotel房间吗?
下一篇:Amazon Intern电面
🔗
 楼主| 心澈非文 2016-1-7 03:33:55 | 只看该作者
全局:
我的接口不一样,maze里面包含了fire和joe。我就合在一起写了。
回复

使用道具 举报

无效楼层,该帖已经被删除
🔗
antonioybw 2016-2-20 04:09:30 | 只看该作者
全局:
请问下楼主, 这个题是在collabedit上写不用compile是吗?

因为我注意到你的代码中不是都是标准函数,所以只要功能逻辑正确就行 无所谓语法?

谢谢
回复

使用道具 举报

全局:
size_t 是什么呀?
回复

使用道具 举报

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

本版积分规则

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