V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
megoo
V2EX  ›  程序员

面试算法题,大家给点思路吧

  •  
  •   megoo · 2015-03-28 14:45:21 +08:00 · 3819 次点击
    这是一个创建于 3310 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Imagine a social network that users can share links. Design a system that is able to present the top 100 shared links within the last 5 minutes, top 100 shared links within the last 10 minutes, and so on。

    10 条回复    2015-03-29 12:31:31 +08:00
    laoyuan
        1
    laoyuan  
       2015-03-28 15:02:14 +08:00
    每分钟查数据库统计这一分钟内 share数前500的 link,作为增量存到一个表里,然后查这个表就行了,要几分钟查几分钟
    laoyuan
        2
    laoyuan  
       2015-03-28 15:02:54 +08:00
    PHP站长拍脑袋解答
    binux
        3
    binux  
       2015-03-28 15:18:58 +08:00
    如果你要精确的,将 link 带个时间戳放个队列,要的时候先去掉超过 10 分钟的数据,然后 merge 一下。
    如果要实用的,每5秒打个包,同上。
    laoyuan
        4
    laoyuan  
       2015-03-28 15:32:17 +08:00
    5秒一包应该不会出什么岔子了
    smalldirector
        5
    smalldirector  
       2015-03-28 15:50:51 +08:00
    flyer103
        6
    flyer103  
       2015-03-28 16:18:04 +08:00   ❤️ 1
    借助 Redis:
    1) 通过 hash 结构存储链接被分享的次数,key 为时间 (单位为 min),field 为 link,value 为 link 在该分钟被分享的次数
    2) 通过 sorted sets 结构计算过去 5min、10min 内被分享的前 TOP N 的链接
    mahone3297
        7
    mahone3297  
       2015-03-28 16:28:11 +08:00
    这个,让我想起了最近看的书
    编写可读代码的艺术,最后一张,讲的基本上就是这个题
    随着这本书不是讲算法的,但是lz可以看看这整个解的过程,蛮赞的。。。
    liuhaotian
        8
    liuhaotian  
       2015-03-28 17:27:17 +08:00
    @Livid 为什么要word-break: break-all啊,留着word-wrap不是看起来比较赏心悦目吗...
    monkeymonkey
        9
    monkeymonkey  
       2015-03-29 09:02:19 +08:00 via Android
    http://blog.csdn.net/v_JULY_v/article/details/6256463
    和这篇文章中的题目基本一样
    laoyuan
        10
    laoyuan  
       2015-03-29 12:31:31 +08:00
    @mahone3297
    看到目录了:第15章 设计并改进“分钟/小时计数器”
    我的方案和 尝试1:一个幼稚的方案 差距大么?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   890 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:01 · PVG 06:01 · LAX 15:01 · JFK 18:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.