logo

实现站点 5 分钟内 hit 计数:`log_hit()` 记录一次访问;`get_hits_in_last_five_minutes()` 返回最近 5 分钟总访问量。

Implement a 5-minute hit counter: `log_hit()` records a hit; `get_hits_in_last_five_minutes()` returns hits in the last five minutes.

题目类型: 技术面试题

这是一道技术面试题,常见于澳洲IT公司面试中。

难度: medium

标签: Dropbox, Sliding Window, Queue

目标岗位: Front End Developer, Front End Engineer, Web Developer

目标公司: Dropbox

参考答案摘要

答案(滑动窗口 + 队列/环形缓冲) 目标: 高频写入 + 快速查询最近 300 秒的总量。 方案 A:队列(最直观) log_hit(ts) :把时间戳入队。 get_hits... :把队首所有 < now-300s 的弹出;返回队列长度。 均摊 O(1)。 参考实现(JS) class HitCounter { constructor(windowSec = 300) { this.wind...

本题提供 STAR 原则详细解答和技术解析,登录匠人学院学习中心即可查看完整答案。

← 返回面试题库

实现站点 5 分钟内 hit 计数:`log_hit()` 记录一次访问;`get_hits_in_last_five_minutes()` 返回最近 5 分钟总访问量。

Mediumalgorithmjavascriptdata-structures

想查看完整答案?

登录匠人学院学习中心,获取 STAR 格式回答和详细技术解析

前往学习中心查看答案