G面经: Design Stock Price Display System
Implement a simple stock price display systemwhich will show High, Low and Last price for a given stock throughout one day.The data comes from a real-time feed and have the following messages:
PriceUpdate(t, P) -> Price of Stock A at timet is P.
Correction(t, NewP) -> Price of Stock A attime t is rectified to NewP
Remove(t) -> Disregard the price feedreceived at time t.
PriceUpdate(10100,850.50) -> high = 850.50, Low = 850.50, Last = 850.50
PriceUpdate(10200,852.25) -> high = 852.25, Low = 850.50, Last = 852.25
PriceUpdate(10300,848.00) -> high = 852.25, Low = 848.00, Last = 848.00
Correction(10200, 849.00) -> high = 850.50, Low = 848.00, Last 848.00
PriceUpdate(10400,855.00) -> high = 855.00, Low = 848.00, Last = 855.00
Correction(10300, 853.00) -> high = 855.00, Low = 850.50, Last = 855.00
PriceUpdate(10500,854.00) -> high = 855.00, Low = 848.00, Last = 854.00
Correction(10500,853.25) -> high = 855.00, Low = 848.00, Last = 853.25
Remove(10300) -> high = 855.00, Low = 849.00, Last = 853.25 简单说来PriceUpdate就是添加新的(timestamp, price), Correction是改之前的(timestamp, price), 求实现当前high(), low(), last()
1. TreeMap<Long, Double> time2priceMap.
2. TreeMap<Double, Integer> price2countMap
priceupdate: insert new record into time2priceMap, update price count in price2countmap
correction: update record in time2pricemap, update prev price count, update prev price count (if 0, remove record), update new price count or needs to insert a new price record into price2countmap
high and low: lastkey and firstkey from price2countmap
last: last entry's price from time2pricemap
补充内容 (2017-2-4 07:00):
这样好像都是O(log(n))
G面经: Design Stock Price Display System的更多相关文章
- 《The Design of a Practical System for Fault-Tolerant Virtual Machines》论文总结
VM-FT 论文总结 说明:本文为论文 <The Design of a Practical System for Fault-Tolerant Virtual Machines> 的个人 ...
- 《The Design of a Practical System for Fault-Tolerant Virtual Machines》论文研读
VM-FT 论文研读 说明:本文为论文 <The Design of a Practical System for Fault-Tolerant Virtual Machines> 的个人 ...
- 17.观察者模式(Observer Pattern)
using System; using System.Collections.Generic; namespace ConsoleApplication10 { /// <summary> ...
- [LeetCode] Design Search Autocomplete System 设计搜索自动补全系统
Design a search autocomplete system for a search engine. Users may input a sentence (at least one wo ...
- [LeetCode] Design Log Storage System 设计日志存储系统
You are given several logs that each log contains a unique id and timestamp. Timestamp is a string t ...
- [LeetCode] Design In-Memory File System 设计内存文件系统
Design an in-memory file system to simulate the following functions: ls: Given a path in string form ...
- LeetCode Design Log Storage System
原题链接在这里:https://leetcode.com/problems/design-log-storage-system/description/ 题目: You are given sever ...
- [LeetCode] 642. Design Search Autocomplete System 设计搜索自动补全系统
Design a search autocomplete system for a search engine. Users may input a sentence (at least one wo ...
- Design In-Memory File System
Design an in-memory file system to simulate the following functions: ls: Given a path in string form ...
随机推荐
- Centos6的yum源
更换原因: yum -y install fping 1.阿里云Linux安装软件镜像源 常用的源: 阿里云是最近新出的一个镜像源.得益与阿里云的高速发展,这么大的需求,肯定会推出自己的镜像源.阿里云 ...
- python实现FTP程序
python实现FTP程序 程序源码 上传功能 查看文件 cd功能 创建目录 程序源码 目录结构 服务端 主程序 import optparse import socketserver import ...
- java SSM 解决跨域问题
什么是跨域 跨域是指从一个域名的网页去请求另一个域名的资源.比如从www.baidu.com 页面去请求 www.google.com 的资源.跨域的严格一点的定义是:只要 协议,域名,端口有任何一个 ...
- Phone List 字典树 OR STL
Phone List Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 140 Solved: 35 Description ...
- 写一个带文本菜单的程序,菜单项如下 (1) 取五个数的和 (2) 取五个数的平均值 (X) 退出。
问题: 写一个带文本菜单的程序,菜单项如下(1) 取五个数的和 (2) 取五个数的平均值(X) 退出. 由用户做一个选择, 然后执行相应的功能.当用户选择退出时程序结束. 实现: ...
- 搜素题 --java
Poj2531 首先把所有节点都放在一组,然后采用深度优先搜索的方法,对每一个节点都做判断是否应该移到另一组去,判断的依据是移过去和不移过去哪个得到的和值比较大(这里移去B组后的计算方法就是加上该点和 ...
- JS对象1
1 String对象 字符串创建 (1) 直接创建 var s="hello"; console.log(s); console.log(typeof s) >> he ...
- 06_ for 练习 _ 年利率
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- 10.1jihe
两种操作,1是加入数字,二是找最接近的 用set或者平衡二叉树就好了 只写了二叉树的,套版子就好 #include<bits/stdc++.h> #define sf scanf #def ...
- FastDFS 分布式文件系统的安装与使用(单节点)
FastDFS 分布式文件系统的安装与使用(单节点) 跟踪服务器:192.168.4.121 (edu-dfs-tracker-01) 存储服务器:192.168.4.125 (edu-dfs-sto ...