由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 这题怎么做啊?
相关主题
interval tree vs. merge intervals请教一道google的数组遍历题
请教一道题find kth smallest key in BST with O(lgn)
L家这题咋搞,巨变态Google Onsite被吊打经过,顺便求referral
CLRS上的interval search问题来个bit题
一个set,有add(i), del(i), count(i), size。写random()。请教一题,关于interval
这道linkedin题是不是应该用segment tree?leetcode这题太搞了
问个Facebook 电面题[合集] M$ interview question
Interval tree解法[合集] 【讨论】两道非常难的Google面试题
相关话题的讨论汇总
话题: time话题: interval话题: tree话题: start话题: end
进入JobHunting版参与讨论
1 (共1页)
b**********5
发帖数: 7881
a*****u
发帖数: 1712
2
应该是要用interval tree。不过如果其他常见题目还没准备好,可以先不专研这个,
有点太小众了
b**********5
发帖数: 7881
3
interval tree我知道, 但还是做不出less than O(n^2).

【在 a*****u 的大作中提到】
: 应该是要用interval tree。不过如果其他常见题目还没准备好,可以先不专研这个,
: 有点太小众了

c*****e
发帖数: 59
4
This is my solution.
first, sort the ids in terms of start time in ascending order
second, sort the ids in terms of end time in descending order
if the interval of one id_A falls into the interval of another id_B, then
the start time of id_A should be after that of id_B, and the end time of id_
B should be after that of id_A.
Therefore, we can use two loops to find out the number of ids that fall into
any given id by searching the ordered id sequences.
Time complexity is O(2log(n)+n^2) ~ O(n^2)
For the given example,
http://discuss.leetcode.com/questions/2274/count-number-of-over
Start time sequence: 1 2 5 4 3
End time sequence: 2 5 3 1 4
output:
3 0
4 0
1 1 //id 4 falls in id 1;
5 2 //id 3,4 fall in id 5;
2 3 //id 5,4,3 fall in id 2
b**********5
发帖数: 7881
5
人家是要小于n^2

id_
into

【在 c*****e 的大作中提到】
: This is my solution.
: first, sort the ids in terms of start time in ascending order
: second, sort the ids in terms of end time in descending order
: if the interval of one id_A falls into the interval of another id_B, then
: the start time of id_A should be after that of id_B, and the end time of id_
: B should be after that of id_A.
: Therefore, we can use two loops to find out the number of ids that fall into
: any given id by searching the ordered id sequences.
: Time complexity is O(2log(n)+n^2) ~ O(n^2)
: For the given example,

e*******8
发帖数: 94
x***y
发帖数: 633
7
interval tree for sure O(nlogn). Check how interval tree gets log(n) time
for inertion and deletion.
s****n
发帖数: 70
8
Not for sure...
如果用>表示包含关系,那么如果是这种情况
i1 > i2 > i3 > ... > in
用interval tree的话查询i1要遍历所有n个叶节点,查询i2要遍历至少n-1个节点。。
。以此类推,一共要访问O(n^2)叶节点。

【在 x***y 的大作中提到】
: interval tree for sure O(nlogn). Check how interval tree gets log(n) time
: for inertion and deletion.

e*******8
发帖数: 94
9
直接单用interval tree的确不行,但是这种partition tree一般好象都可以augment吧
(就是把解决reporting问题的data structure augment成解决counting问题的data
structure),不过我也没想清楚interval tree对这个问题应该怎么augment..
segment tree倒是可以用,但是又总觉得用segment tree+fenwick tree有点杀鸡焉用
割牛刀的感觉...

【在 s****n 的大作中提到】
: Not for sure...
: 如果用>表示包含关系,那么如果是这种情况
: i1 > i2 > i3 > ... > in
: 用interval tree的话查询i1要遍历所有n个叶节点,查询i2要遍历至少n-1个节点。。
: 。以此类推,一共要访问O(n^2)叶节点。

1 (共1页)
进入JobHunting版参与讨论
相关主题
[合集] 【讨论】两道非常难的Google面试题一个set,有add(i), del(i), count(i), size。写random()。
C++ 程序求助这道linkedin题是不是应该用segment tree?
如何回答这题:how to explain binary search tree to a 5 year old child问个Facebook 电面题
这题咋做啊?Interval tree解法
interval tree vs. merge intervals请教一道google的数组遍历题
请教一道题find kth smallest key in BST with O(lgn)
L家这题咋搞,巨变态Google Onsite被吊打经过,顺便求referral
CLRS上的interval search问题来个bit题
相关话题的讨论汇总
话题: time话题: interval话题: tree话题: start话题: end