由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Discuss: A google binary search problem
相关主题
一道google 经典题报M家卧佛+onsite面经
问下Linkedin的一道电面请问这个3sumClosest
问个算法题,修改版最新L家面经
Discuss: best way to serialize binary tree? (without the special character)Part-time Mandarin teacher in Lebanon, NJ
Verify Preorder Sequence in Binary Search Tree总是忘记思路这能算是offer吗?
也上一道算法题了(俺的版权了:))leetcode的old discuss不见了
Microsoft screening programming problem下面这种情况该如何处理?
给个float BST, 写个search(float target)的算法找出离target最近的数。E-verify question with baozi
相关话题的讨论汇总
话题: dist话题: min话题: binary话题: search话题: verify
进入JobHunting版参与讨论
1 (共1页)
s**********r
发帖数: 141
1
I saw there's a long discussion on the following problem (I modified the
description a bit).
"给一个整数数组a[0...n],找出一个size k(1 distance中,使得其min distance 最大化 (max-mindist)."
It bothered me for a while (Simply I am not a DP fan). I consider it as a
binary search problem:
0. Sort the array in ascending order. O(nlogn)
1. If you claim the max-mindist is w, I can verify it in O(n).
2. Note that '0 <= w <= (a[n]-a[0])', you can try possible w's using
binary search.
3. Time comple
P*******e
发帖数: 1353
2
how do you verify 1 in O(n)?

pair-

【在 s**********r 的大作中提到】
: I saw there's a long discussion on the following problem (I modified the
: description a bit).
: "给一个整数数组a[0...n],找出一个size k(1: distance中,使得其min distance 最大化 (max-mindist)."
: It bothered me for a while (Simply I am not a DP fan). I consider it as a
: binary search problem:
: 0. Sort the array in ascending order. O(nlogn)
: 1. If you claim the max-mindist is w, I can verify it in O(n).
: 2. Note that '0 <= w <= (a[n]-a[0])', you can try possible w's using
: binary search.

f*****s
发帖数: 29
3
dynamic programming

pair-

【在 s**********r 的大作中提到】
: I saw there's a long discussion on the following problem (I modified the
: description a bit).
: "给一个整数数组a[0...n],找出一个size k(1: distance中,使得其min distance 最大化 (max-mindist)."
: It bothered me for a while (Simply I am not a DP fan). I consider it as a
: binary search problem:
: 0. Sort the array in ascending order. O(nlogn)
: 1. If you claim the max-mindist is w, I can verify it in O(n).
: 2. Note that '0 <= w <= (a[n]-a[0])', you can try possible w's using
: binary search.

k*i
发帖数: 220
4
能详细说说吗?

【在 f*****s 的大作中提到】
: dynamic programming
:
: pair-

s**********r
发帖数: 141
5
// Verify whether the window (min-dist) 'w' is valid.
// Note: v is already sorted.
bool verify(const std::vector &v, int k, int w) {
int e = v.size();
if (e < 2 || k > e) { err(); return false; }

int i = 0, j = 1;
while (j < e) {
while(v[j] - v[i] < w) {
if (++j >= e) { break; }
}
if (j < e) { i = j; ++j; --k; }
}
return k > 1 ? false : true;
}

【在 P*******e 的大作中提到】
: how do you verify 1 in O(n)?
:
: pair-

m*****k
发帖数: 64
6
能举例吗?

pair-
a

【在 s**********r 的大作中提到】
: I saw there's a long discussion on the following problem (I modified the
: description a bit).
: "给一个整数数组a[0...n],找出一个size k(1: distance中,使得其min distance 最大化 (max-mindist)."
: It bothered me for a while (Simply I am not a DP fan). I consider it as a
: binary search problem:
: 0. Sort the array in ascending order. O(nlogn)
: 1. If you claim the max-mindist is w, I can verify it in O(n).
: 2. Note that '0 <= w <= (a[n]-a[0])', you can try possible w's using
: binary search.

s**********r
发帖数: 141
7
Key observation:
if there's a sequence S (S[0] < S[1] < ... < S[k-1]) which has size k and
it's min-dist is w in sorted array A, then we can derive another sequence
Z (Z[0] < Z[1] < ... < Z[k-1]) with size k, and Z has min-dist w1 >= w.
Hint: Since S[0] >= A[0], if you substitute S[0] with A[0], and the
sequence S now has min-dist >= w; you can move one more step to
substitutes S[1] with A[j] s.t. A[j] >= A[0]+w and A[j-1] < A[0]+w, and
the sequence now still has min-dist >=w. Pushing this idea
p*****u
发帖数: 310
8
Nice solution. Anyone know dp solution?
p*****u
发帖数: 310
9
Nice solution. Anyone know dp solution?
s**********r
发帖数: 141
10
http://www.mitbbs.com/article_t/JobHunting/31540541.html

【在 p*****u 的大作中提到】
: Nice solution. Anyone know dp solution?
1 (共1页)
进入JobHunting版参与讨论
相关主题
E-verify question with baoziVerify Preorder Sequence in Binary Search Tree总是忘记思路
学校的工作属于E-verify吗?也上一道算法题了(俺的版权了:))
amazon questionMicrosoft screening programming problem
Can I extend my OPT if my employer uses E-verify?给个float BST, 写个search(float target)的算法找出离target最近的数。
一道google 经典题报M家卧佛+onsite面经
问下Linkedin的一道电面请问这个3sumClosest
问个算法题,修改版最新L家面经
Discuss: best way to serialize binary tree? (without the special character)Part-time Mandarin teacher in Lebanon, NJ
相关话题的讨论汇总
话题: dist话题: min话题: binary话题: search话题: verify