📣 Back to School开学季 - VIP通行证5折优惠!蓝莓、Offer多多同步优惠
12
返回列表 发新帖
楼主: duduhaha
跳转到指定楼层
上一主题 下一主题
收起左侧

一道google的题目,至今没看到正确答案。

🔗
Kimurate 2016-5-29 01:10:16 | 只看该作者
全局:
d=2的话就是隔一个吧?"aaaabbbcc" -> "ababacabc",可以用贪心啊。
回复

使用道具 举报

🔗
qinqinhao 2016-5-29 10:34:11 | 只看该作者
全局:
题目没有说清楚是at-least-d-distance还是exact-d-distance
后者的话答案是bababacac
回复

使用道具 举报

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

使用道具 举报

🔗
qinqinhao 2016-5-30 04:45:07 | 只看该作者
全局:
请教exact如何做...
回复

使用道具 举报

🔗
wangmengcathy 2016-5-30 12:47:42 | 只看该作者
全局:
这是道FB题吧 当年面FB的时候做过。。贪心应该是可解的。。
  1. public static String taskScheduler(String tasks, int n) {
  2.                 StringBuilder sb = new StringBuilder();
  3.                 HashMap<Character, Integer> countMap = new HashMap<Character, Integer>();
  4.                 for(char c : tasks.toCharArray()) countMap.put(c, countMap.containsKey(c) ? countMap.get(c) + 1 : 1);
  5.                 // sort the task by their occurence time (N/c * c *logk)
  6.                 PriorityQueue<Map.Entry<Character, Integer>> queue = new PriorityQueue<>(new Comparator<Map.Entry<Character, Integer>>(){
  7.                         public int compare(Map.Entry<Character,Integer> e1, Map.Entry<Character,Integer> e2) {
  8.                                 return e2.getValue() - e1.getValue();
  9.                         }
  10.                 });

  11.                 for(Map.Entry entry : countMap.entrySet()) queue.offer(entry);
  12.                
  13.                 while(!queue.isEmpty()) {
  14.                         List<Map.Entry> refill = new ArrayList<Map.Entry>();
  15.                         int i = 0;
  16.                         for(i = 0; i < n && !queue.isEmpty(); i++) {
  17.                                 Map.Entry e = queue.poll();
  18.                                 sb.append(e.getKey());
  19.                                 int count = (Integer)e.getValue();
  20.                                 if(count > 1) refill.add(new AbstractMap.SimpleEntry<Character, Integer>((Character)e.getKey(), count - 1));
  21.                         }
  22.                         while(i++ < n && refill.size() > 0) sb.append("_");
  23.                         // refill the task which hasn't finished yet
  24.                         for(Map.Entry e : refill) queue.offer(e);
  25.                 }
  26.                 return sb.toString();
  27.         }
复制代码

评分

参与人数 1大米 +50 收起 理由
Kimurate + 50 感谢分享!

查看全部评分

回复

使用道具 举报

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

使用道具 举报

🔗
tigercode 2016-9-12 00:29:45 | 只看该作者
全局:
除了maxheap, 同事维护一个size = d-1的queue就行,(d如果等于2就相当于另外一道题,不能连续,这种情况其实可以不用queue,直接check一下Peek的character是不是等于last string position的就行)
回复

使用道具 举报

🔗
heroic 2016-9-12 01:25:46 | 只看该作者
全局:
直接用256大小数组表示string啊 每次找最大值也是O(1)的时间,其实对于所有有限的字母 字符串 直接开数组用下标计数会比hashmap或heap快很多。
回复

使用道具 举报

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

本版积分规则

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