📣 黑五价提前开抢|VIP一年通行证5折,蓝莓、Offer多多同步特惠
回复: 12
跳转到指定楼层
上一主题 下一主题
收起左侧

UBER电面

全局:

2015(7-9月) 码农类General 硕士 全职@uber - 内推 - 技术电面  | | Other | 其他

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

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

x
两个月前约过两次电面,都被放鸽子了。昨天recruiter又联系我,约的今天电面。
两道题:
1. 给一个string list, 例如:['a', 'b', 'b', 'c', 'c', 'e', 'e', 'e'],返回出次次数是中位数的字符。例如本题,应该返回[b,
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
做。大家有谁看懂了这道题的,欢迎一起讨论~


补充内容 (2015-7-15 07:29):
补充一下,是同时最多抓取5个url。

上一篇:Google new grad phone Interview
下一篇:pocketgem店面第一轮~
推荐
yhfyhf 2015-7-15 10:50:35 | 只看该作者
全局:
想了一下,貌似没必要用闭包,直接用yield和generator就行了...
  1. def crawling(url):
  2.     print("crawling %s" % url)


  3. def get_crawling_url():
  4.     a = []
  5.     for x in xrange(100):
  6.         a.append('google.com/'+str(x))
  7.     return a


  8. def crawling_max_k(list_of_url, k=5):
  9.     iter_of_url = iter(list_of_url)

  10.     def _crawling_k():
  11.         for i in xrange(k):
  12.             try:
  13.                 crawling(iter_of_url.next())
  14.             except StopIteration:
  15.                 return

  16.     return _crawling_k


  17. def crawling_max_k_using_generator(list_of_url, k=5):
  18.     for idx, url in enumerate(list_of_url):
  19.         crawling(url)
  20.         if idx % k == k - 1:
  21.             yield


  22. if __name__ == '__main__':
  23.     list_of_url = get_crawling_url()
  24.     c5 = crawling_max_k(list_of_url)
  25.     c5()
  26.     c5()

  27.     print '*' * 30
  28.     c5_gen = crawling_max_k_using_generator(list_of_url)
  29.     c5_gen.next()
  30.     c5_gen.next()
复制代码
回复

使用道具 举报

全局:
写了下第一题
  1. public class MedianOccurence {

  2.         static class Ele {
  3.                 char c ;
  4.                 int times;
  5.                 public Ele(char c, int t) {
  6.                         this.c = c;
  7.                         times = t;
  8.                 }
  9.         }
  10.        
  11.         public static List<Character> getMedianOccurenceCharactr(char[] chars) {
  12.                 List<Character> res = new ArrayList<Character>();
  13.                 if (chars == null || chars.length == 0) {
  14.                         return res;
  15.                 }
  16.                 HashMap<Character, Integer> map = new HashMap<Character, Integer>();
  17.                 for (char c : chars) {
  18.                         if (map.containsKey(c)) {
  19.                                 map.put(c, map.get(c) + 1);
  20.                         } else {
  21.                                 map.put(c, 1);
  22.                         }
  23.                 }
  24.                 Ele[] eles = new Ele[map.size()];
  25.                 int index = 0;
  26.                 for (Entry<Character, Integer> entry : map.entrySet()) {
  27.                         eles[index++] = new Ele(entry.getKey(), entry.getValue());
  28.                 }
  29.                 int median = getMedian(eles, 0, eles.length - 1);
  30.                 for (Ele ele : eles) {
  31.                         if (ele.times == median) {
  32.                                 res.add(ele.c);
  33.                         }
  34.                 }
  35.                
  36.                 return res;
  37.         }
  38.         private static int getMedian(Ele[] eles, int start, int end) {
  39.                 int k = (eles.length - 1) / 2;
  40.                 int index = parition(eles, start, end);
  41.                 if (index == k) {
  42.                         return eles[index].times;
  43.                 } else if (index > k) {
  44.                         return getMedian(eles, start, index - 1);
  45.                 } else {
  46.                         return getMedian(eles, index + 1, end);
  47.                 }
  48.         }
  49.         private static int parition(Ele[] eles, int start, int end) {
  50.                 int pivot = start;
  51.                 int i = start;
  52.                 int j = start + 1;
  53.                 while (j <= end) {
  54.                         if (eles[j].times < eles[pivot].times) {
  55.                                 i++;
  56.                                 swap(eles, i, j);
  57.                         }
  58.                         j++;
  59.                 }
  60.                 swap(eles, i, pivot);
  61.                 return i;
  62.         }
  63.         private static void swap(Ele[] eles, int i, int j) {
  64.                 Ele tmp = eles[i];
  65.                 eles[i] = eles[j];
  66.                 eles[j] = tmp;
  67.         }
  68.        
  69.         public static void main(String[] args) {
  70.                 char[] chars = {'a', 'b', 'b','c', 'c', 'c', 'e', 'e', 'e', 'd', 'd', 'd', 'd'};
  71.                 List<Character> res = getMedianOccurenceCharactr(chars);
  72.                 for (char c : res) {
  73.                         System.out.println(c);
  74.                 }
  75.         }
  76.        
  77. }
复制代码
回复

使用道具 举报

🔗
readman 2015-7-15 07:13:52 | 只看该作者
全局:
根据什么的解析? 最多抓取5次 5次还是5个..?
回复

使用道具 举报

🔗
 楼主| catfiona 2015-7-15 07:26:08 | 只看该作者
全局:
readman 发表于 2015-7-15 07:13
根据什么的解析? 最多抓取5次 5次还是5个..?

是同时最多解析5个url,次数是直到解析完。
回复

使用道具 举报

🔗
mkcing 2015-7-15 07:34:53 | 只看该作者
全局:
第一题怎么做呢?
回复

使用道具 举报

🔗
readman 2015-7-15 07:47:27 | 只看该作者
全局:
mkcing 发表于 2015-7-15 07:34
第一题怎么做呢?

one pass 记下每个string的次数,用char[].
然后quickselect
回复

使用道具 举报

🔗
readman 2015-7-15 07:49:25 | 只看该作者
全局:
mkcing 发表于 2015-7-15 07:34
第一题怎么做呢?

Median of medians
回复

使用道具 举报

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

使用道具 举报

🔗
yhfyhf 2015-7-15 10:14:13 | 只看该作者
全局:
我猜这题是考闭包?

  1. def crawling(url):
  2.     print("crawling %s" % url)


  3. def get_crawling_url():
  4.     a = []
  5.     for x in xrange(100):
  6.         a.append('google.com/'+str(x))
  7.     return a


  8. def crawling_max_k(list_of_url, k=5):
  9.     iter_of_url = iter(list_of_url)

  10.     def _crawling_k():
  11.         for i in xrange(k):
  12.             try:
  13.                 crawling(iter_of_url.next())
  14.             except StopIteration:
  15.                 return

  16.     return _crawling_k


  17. if __name__ == '__main__':
  18.     list_of_url = get_crawling_url()
  19.     c5 = crawling_max_k(list_of_url)
  20.     c5()
  21.     c5()
复制代码
回复

使用道具 举报

🔗
 楼主| catfiona 2015-7-16 04:18:21 | 只看该作者
全局:
yhfyhf 发表于 2015-7-15 10:50
想了一下,貌似没必要用闭包,直接用yield和generator就行了...

赞!我先学习一下!
回复

使用道具 举报

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

本版积分规则

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