由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 大家看看这个题目改怎么做。
相关主题
问道G题(2)帮忙看道题:[leetcode] word break
bloomberg 问题: C++ construct 时用 new 没"()"Analyst Information Technology (Lilly, IN)
Apple Onsite?adobe coding Test
请教OPT 问题问一个C++ set和unordered_set iterator的问题
我的opt好慢C++定义数组长度可以写成int a[n]吗?
CSC OPT 两个半月了还是initialA problem about Heap and Stack.
opt从initial review到decision一般多久FLAG面试总结
今年4月递交H1B,还没有批a small question about c++ object allocation
相关话题的讨论汇总
话题: isrushhour话题: time话题: false话题: true
进入JobHunting版参与讨论
1 (共1页)
i******t
发帖数: 798
1
我想用interval tree 作, 不知道思路对不对 .
用 interval tree 原理 应该可以把但是 可能不能满足 效率问题?
thanks
Scenario:
---------
In our server farm, there are certain times of day in which we get a higher
number of requests. During these time-spans we want to respond by allocating
more resources, to give better service. Outside these time-spans we want to
remove resources, to save on energy.
We need to be able to know which times of day are such "Rush Hours".
Your task:
----------
Write a class which can receive time-spans that are defined as "Rush Hours",
remember them, and can also answer queries about a specific time of day -
whether it is considered rush hour or not.
The class provides the following interfaces:
1. void AddTimeSpan(float start_time, float end_time);
2. boolean IsRushHour(float time);
Assumptions:
------------
. When the class is initialized, there are no rush hours at all. The user
can then add time-spans of rush hours using the "AddTimeSpan" interface. The
user can at any time query about a specific time using the "IsRushHour"
interface.
. Assume that "IsRushHour" is called very frequently, and "AddTimeSpan" is
called less frequently.
. Assume that the system will live forever, and performance should not
degrade over time.
. float T is a valid time of day if (T>=0.00 and T<24.00). You can not
assume anything about the input. You must support any valid time.
. If the input is invalid (meaning T<0 or T>=24.00), behvaiour is not
defined.
. IMPORTANT: The internal representation of time spans must be minimal. For
example, if the same time span is added twice, there should be no change to
the internal data structures.
Usage Example:
--------------
- Init() // System is initialized in an empty state
- IsRushHour(3.00) --> False
- IsRushHour(5.00) --> False
- AddTimeSpan(2.00, 4.00)
- IsRushHour(3.00) --> True
- IsRushHour(5.00) --> False
- AddTimeSpan(7.00, 9.00)
- IsRushHour(3.00) --> True
- IsRushHour(5.00) --> False
- IsRushHour(7.00) --> True
- IsRushHour(11.00) --> False
- AddTimeSpan(8.00, 12.00)
- IsRushHour(3.00) --> True
- IsRushHour(5.00) --> False
- IsRushHour(7.00) --> True
- IsRushHour(11.00) --> True
w*********4
发帖数: 832
2
Maintain a list of sorted intervals.
AddInterval: merge added interval to sorted intervals - O(n)
IsRushHour: find the maximum start time that is smaller or equal to input
using binary search O(logn)
w*********4
发帖数: 832
3
Interval tree add时间效率更高些,但是似乎不满足minimal data representation的
要求?
1 (共1页)
进入JobHunting版参与讨论
相关主题
a small question about c++ object allocation我的opt好慢
Char x[] = "abc"; 是在heap还是stack上? (转载)CSC OPT 两个半月了还是initial
请教个C++编程思路opt从initial review到decision一般多久
为什么C++的constructor出错可以抛出异常,而destructor出错今年4月递交H1B,还没有批
问道G题(2)帮忙看道题:[leetcode] word break
bloomberg 问题: C++ construct 时用 new 没"()"Analyst Information Technology (Lilly, IN)
Apple Onsite?adobe coding Test
请教OPT 问题问一个C++ set和unordered_set iterator的问题
相关话题的讨论汇总
话题: isrushhour话题: time话题: false话题: true