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

脸书3月9日跪经

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

使用道具 举报

🔗
30048686 2017-3-16 13:16:39 | 只看该作者
全局:
lz其他几面都是hire只有design是no hire就挂了吗?
回复

使用道具 举报

🔗
 楼主| Zhenying 2017-3-16 13:33:50 | 只看该作者
全局:
30048686 发表于 2017-3-16 13:16
lz其他几面都是hire只有design是no hire就挂了吗?

recuriter没和我细说,我也不是很清楚。
回复

使用道具 举报

🔗
 楼主| Zhenying 2017-3-16 13:34:32 | 只看该作者
全局:
whyz 发表于 2017-3-15 14:06
感谢分享 bless楼主能早日团聚!

谢谢~字数字数字数
回复

使用道具 举报

🔗
 楼主| Zhenying 2017-3-16 13:35:39 | 只看该作者
全局:
bobyuwenchen 发表于 2017-3-15 14:08
lz move on,为妹子攒人品~我也是3.9号onsite的 不过是newgrad 所以三轮只有半天 面完感觉不是很好 到现在 ...

谢谢~我是发邮件催了下。没消息就是好消息啊,加油~
回复

使用道具 举报

🔗
 楼主| Zhenying 2017-3-16 13:37:16 | 只看该作者
全局:
Zhenying 发表于 2017-3-16 12:47
我是定义了这么一个结构,然后数每个task出现的次数,作为cnt。然后做一个很大的数组,然后每次取出出现 ...

顺手写了下代码,感觉比leetcode那道题还简单一些。不知道有没有什么bug。
  1. #include <iostream>
  2. #include <unordered_map>
  3. #include <queue>

  4. using namespace std;

  5. class Solution {
  6. public:
  7.     string rearrangeTask(string tasks, int k) {
  8.         // assume there is only one task, the max length is 1,*,*,1,*,*
  9.         string res( tasks.length() * (k + 1), '*' );

  10.         // count appear times of each task and push them into a max heap
  11.         unordered_map<char, int> task2cnt;
  12.         for (char &t : tasks)
  13.             task2cnt[t]++;
  14.         priority_queue<TaskCnt> maxHeap;
  15.         for (auto it = task2cnt.begin(); it != task2cnt.end(); it++)
  16.             maxHeap.push( {it->first, it->second} );

  17.         // place tasks that appear most times first, because 1,2,*,1 is better than 2,1,*,*,1
  18.         int idx = 0;
  19.         while (!maxHeap.empty()) {
  20.             TaskCnt taskCnt = maxHeap.top();
  21.             maxHeap.pop();
  22.             char task = taskCnt.t;
  23.             int cnt = taskCnt.cnt;

  24.             for (int i = 0; i < cnt; i++) {
  25.                 res[idx] = task;
  26.                 idx = idx + k + 1;
  27.             }

  28.             idx = res.find_first_of("*");
  29.         }

  30.         // remove place holders
  31.         res.erase(res.find_last_not_of("*") + 1);
  32.         return res;
  33.     }

  34. private:
  35.     struct TaskCnt {
  36.         char t;
  37.         int cnt;
  38.         bool operator<(const TaskCnt &other) const {
  39.             return cnt < other.cnt;
  40.         }
  41.     };
  42. };

  43. int main() {
  44.     Solution sol;
  45.     cout << sol.rearrangeTask("1112233", 0) << endl;
  46.     cout << sol.rearrangeTask("1112233", 1) << endl;
  47.     cout << sol.rearrangeTask("1112233", 2) << endl;
  48.     cout << sol.rearrangeTask("1112233", 3) << endl;
  49.     cout << sol.rearrangeTask("11223344", 2) << endl;

  50.     return 0;
  51. }
复制代码
回复

使用道具 举报

🔗
say543 2017-3-16 14:09:56 | 只看该作者
全局:
Zhenying 发表于 2017-3-16 12:37
leetcode那道题我也是刚做,所以还记得。现场想我肯定想不出来。

能问问市leetcode哪一题吗? thanks
回复

使用道具 举报

🔗
wuwei123 2017-3-16 15:01:54 | 只看该作者
全局:
followup leetcode 358
回复

使用道具 举报

🔗
lhh_NJU 2017-3-16 15:08:00 | 只看该作者
全局:
Zhenying 发表于 2017-3-16 12:47
我是定义了这么一个结构,然后数每个task出现的次数,作为cnt。然后做一个很大的数组,然后每次取出出现 ...

但是如果有4种任务, 每个都出现3次怎么办? 这种情况得插入吧..
回复

使用道具 举报

🔗
30048686 2017-3-16 15:09:26 | 只看该作者
全局:
Zhenying 发表于 2017-3-16 13:33
recuriter没和我细说,我也不是很清楚。

谢谢lz
lz加油
看你好几个面经,感觉实力还是很强的,看起来都是细节问题。相信你会拿到offer的。
回复

使用道具 举报

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

本版积分规则

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