Input (stdin)
The program reads the input line by line. Each line must be one of the following message types:
• A print represents a trade that took place on the exchange:
print <timestamp> <security> <quantity> <price>
• A volume check is a request to report the total traded quantities of a security in the preceding minute, as well as its latest price:
volume-check <timestamp> <security>
Fields are space-delimited and defined as follows:
- timestamp: seconds since market open (non-negative integer). Timestamps are guaranteed to be monotonically non-decreasing.
- security: alphabetical string.
- quantity: positive integer.
- price: positive integer.
Output (stdout)
For each volume check request for security S at time T, emit the following line:
traded-volume T S <volume> <price>
Where:
- volume = sum of traded quantities in all prints of S whose timestamps > T-60 (zero if none)
- price = price in the most recent print for S (zero if none)
Volume check responses must be emitted before processing subsequent input.
Example
Input
print 9 SILVER 30 11
print 12 SILVER 100 12
print 29 PEARL 25 99
print 37 SILVER 10 14
volume-check 69 SILVER
print 71 PEARL 25 100
volume-check 99 SILVER
volume-check 99 PEARL
Output
traded-volume 69 SILVER 110 14
traded-volume 99 SILVER 0 0
traded-volume 99 PEARL 25 100
✅ 总结(面试官想考什么)
这题考察你是否能实现:
✅ 滑动窗口(过去 60 秒)
✅ 按 security 分桶管理成交数据
✅ 维护最新成交价格
✅ 按时间顺序实时处理输入(类似流式系统)
重点难点:
- 每次 volume-check 只统计最近 60 秒的成交量
- timestamp 不递减 → 可安全用队列
- 多个 security 并行 → 字典 + 队列结构
- 要先输出 volume-check 结果,再继续处理输入(流式处理)
适合用 HashMap<security, deque(trades)>。
VOprep 团队长期陪同学员实战各类大厂 OA 与 VO,包括 Voleon、Google、Amazon、Citadel、SIG 等,提供实时答案助攻、远程陪练与面试节奏提醒,帮助大家在关键时刻不卡壳。
如果你也在准备 Tiktok 或类似工程向公司,可以了解一下我们的定制助攻方案——从编程面到系统设计,全程护航上岸。