由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 昨天面试的题目
相关主题
问F家一道题多年不打鱼连网都不会用了
please help 这个题 (转载)Bloomberg 电面面经,EE专业
问一道排序题MS a0, a1, ..., b0, b1... 问题
问道难的scheduling问题请教一道google的数组遍历题
贡献一个MS onsite面试题求问Jane Street一道面试题
Search for a Range - leetcode2SUM, unsorted, print all index including duplicates 能O(nlogn)解决么
请教一道算法题,非Brute Force, 谢谢!F家intern面经
问个算法题, 关于区间 overlap的做题
相关话题的讨论汇总
话题: range话题: upp话题: boundary话题: ranges话题: list
进入JobHunting版参与讨论
1 (共1页)
s*****r
发帖数: 773
1
一个很小的公司, 要我一个小时写个程序发过去, 用了一个很simple的算法,就是从给
定range的每个integer对比一个range一个range的看, 大家看看这题如果要efficient
怎么弄?
Write a function that takes a list of integer ranges and an additional range
and prints all non-overlapping ranges from the additional range.
For example, given a list or ranges [6 – 10], [17 – 24], [15 – 19] and a
new range [8 – 28], your function should print [11 – 14], [25 - 28].
c*********n
发帖数: 1057
2
根据第一个数排序,然后一个个range往后比对,维护一个global right bound,
每次都把这个right bound和rang的left value比较就好了吧?

efficient
range
a

【在 s*****r 的大作中提到】
: 一个很小的公司, 要我一个小时写个程序发过去, 用了一个很simple的算法,就是从给
: 定range的每个integer对比一个range一个range的看, 大家看看这题如果要efficient
: 怎么弄?
: Write a function that takes a list of integer ranges and an additional range
: and prints all non-overlapping ranges from the additional range.
: For example, given a list or ranges [6 – 10], [17 – 24], [15 – 19] and a
: new range [8 – 28], your function should print [11 – 14], [25 - 28].

m******9
发帖数: 968
3
我的思路是这样的
1. 把new range [8,28] dump到数组A中,使得A[index] = index, 如果没有出现的
value,则设置为-1,即:
分配一个size=29的数组,[8,28]dump到该数组的结果就是:
A[-1,-1,-1,...-1,8,9,10,11,.....28]
2. 一次遍历list of ranges, 凡是能够在A中能够找到的value全部都设定为A[index]=
-1.
例如:对比[6,10]时, A[6]=-1, A[7]=-1; ... A[10]=-1
这样把整个range都遍历完
3. 再次遍历数组A,将A[index]!=-1的全部打印出来
c*********n
发帖数: 1057
4
en这个时间上更快

]=

【在 m******9 的大作中提到】
: 我的思路是这样的
: 1. 把new range [8,28] dump到数组A中,使得A[index] = index, 如果没有出现的
: value,则设置为-1,即:
: 分配一个size=29的数组,[8,28]dump到该数组的结果就是:
: A[-1,-1,-1,...-1,8,9,10,11,.....28]
: 2. 一次遍历list of ranges, 凡是能够在A中能够找到的value全部都设定为A[index]=
: -1.
: 例如:对比[6,10]时, A[6]=-1, A[7]=-1; ... A[10]=-1
: 这样把整个range都遍历完
: 3. 再次遍历数组A,将A[index]!=-1的全部打印出来

s*****r
发帖数: 773
5
这样还是要一个个遍历所有的range, 有没有不需要一个个range遍历的.
另外, 最开始的数组都没有用, 直接for loop 从begin开始到end, 一个个查是否在
range就行了.

]=

【在 m******9 的大作中提到】
: 我的思路是这样的
: 1. 把new range [8,28] dump到数组A中,使得A[index] = index, 如果没有出现的
: value,则设置为-1,即:
: 分配一个size=29的数组,[8,28]dump到该数组的结果就是:
: A[-1,-1,-1,...-1,8,9,10,11,.....28]
: 2. 一次遍历list of ranges, 凡是能够在A中能够找到的value全部都设定为A[index]=
: -1.
: 例如:对比[6,10]时, A[6]=-1, A[7]=-1; ... A[10]=-1
: 这样把整个range都遍历完
: 3. 再次遍历数组A,将A[index]!=-1的全部打印出来

m******9
发帖数: 968
6
嗯,你说的没错,我弄错了。题目是只给个range就够了,并不是一组数。肯定有更好
的方法。

【在 s*****r 的大作中提到】
: 这样还是要一个个遍历所有的range, 有没有不需要一个个range遍历的.
: 另外, 最开始的数组都没有用, 直接for loop 从begin开始到end, 一个个查是否在
: range就行了.
:
: ]=

z**k
发帖数: 629
7
应该先简化第一个Range系列,然后只比较其begin和end,不应该一一遍历.
k***e
发帖数: 556
8
range tree
i don't remember the exact name.
Computational Geometry Algorithms and Applications, chapter 10
nlgn preprocessing, O(lgn+matched#)

efficient
range
a

【在 s*****r 的大作中提到】
: 一个很小的公司, 要我一个小时写个程序发过去, 用了一个很simple的算法,就是从给
: 定range的每个integer对比一个range一个range的看, 大家看看这题如果要efficient
: 怎么弄?
: Write a function that takes a list of integer ranges and an additional range
: and prints all non-overlapping ranges from the additional range.
: For example, given a list or ranges [6 – 10], [17 – 24], [15 – 19] and a
: new range [8 – 28], your function should print [11 – 14], [25 - 28].

m*****f
发帖数: 1243
9
I think the basic idea is sort the range number first by nlogn, then use
binary search to find the two range ends in the sorted list, so you don't
have to check the whole list
just O(logn) + O(matched)

【在 k***e 的大作中提到】
: range tree
: i don't remember the exact name.
: Computational Geometry Algorithms and Applications, chapter 10
: nlgn preprocessing, O(lgn+matched#)
:
: efficient
: range
: a

x***y
发帖数: 633
10
1. Sort the lower boundary, and the upper boundary separately (O(nlogn)),
from the smallest lower boundary min_low (6 in your e.g), and assume upp is
the upper boundary corresponding(10 in e.g) to lower boundary, set old_upp
to min_low;
2. find position of upp in the array of lower boundary, and in the lower
boundary for all the values less than upp, if the largest corresponding
upper bound is bigger than upp, set old_upp to upp and set upp to the
largest corresponding upper bound, and do step

【在 s*****r 的大作中提到】
: 一个很小的公司, 要我一个小时写个程序发过去, 用了一个很simple的算法,就是从给
: 定range的每个integer对比一个range一个range的看, 大家看看这题如果要efficient
: 怎么弄?
: Write a function that takes a list of integer ranges and an additional range
: and prints all non-overlapping ranges from the additional range.
: For example, given a list or ranges [6 – 10], [17 – 24], [15 – 19] and a
: new range [8 – 28], your function should print [11 – 14], [25 - 28].

1 (共1页)
进入JobHunting版参与讨论
相关主题
做题贡献一个MS onsite面试题
请教一道题Search for a Range - leetcode
Google 面试题 一道请教一道算法题,非Brute Force, 谢谢!
问一个时间复杂度的问题,数组里取k个最大数问个算法题, 关于区间 overlap的
问F家一道题多年不打鱼连网都不会用了
please help 这个题 (转载)Bloomberg 电面面经,EE专业
问一道排序题MS a0, a1, ..., b0, b1... 问题
问道难的scheduling问题请教一道google的数组遍历题
相关话题的讨论汇总
话题: range话题: upp话题: boundary话题: ranges话题: list