Maximum Gap
来源:互联网 发布:mac可以玩使命召唤吗 编辑:程序博客网 时间:2024/05/22 17:04
Maximum Gap
Analysis written by @porker2008.
Suppose there are N elements and they range from A toB.
Then the maximum gap will be no smaller than ceiling[(B - A) / (N - 1)]
Let the length of a bucket to be len = ceiling[(B - A) / (N - 1)], then we will have at most num = (B - A) / len + 1 of bucket
for any number K in the array, we can easily find out which bucket it belongs by calculating loc = (K - A) / len and therefore maintain the maximum and minimum elements in each bucket.
Since the maximum difference between elements in the same buckets will be at most len - 1, so the final answer will not be taken from two elements in the same buckets.
For each non-empty buckets p, find the next non-empty buckets q, then q.min - p.max could be the potential answer to the question. Return the maximum of all those values.
- Maximum Gap
- Maximum Gap
- Maximum Gap
- MAXIMUM GAP
- Maximum Gap
- Maximum Gap
- Maximum Gap
- Maximum Gap
- Maximum Gap
- Maximum Gap
- Maximum Gap
- Maximum Gap
- Maximum Gap
- Maximum Gap
- Maximum Gap
- Maximum Gap
- Maximum Gap
- Maximum Gap
- mac10.10配置apache环境
- Eclipse 建立自己的Library
- 12/15/2014-读书笔记-《站在发展的前沿——新一代互联网思维》
- ZOJ3623:Battle Ships(完全背包)
- python压缩和读取.tar.bz2格式的压缩包
- Maximum Gap
- 3D图形数学速成课(NOTE)
- 九度OJ 题目1208:10进制 VS 2进制
- Python下的TK(二)控件之Label
- 根据离散概率随机返回int值java代码&理解
- 设置listContrl中指定行的颜色
- Ubuntu 12.04中MyEclipse 10.6+下载+安装+破解
- Haskell函数式编程基础习题
- 从C开始_结构体_结构指针