由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 面试题
相关主题
Longest Consecutive Sequence 问题释疑请教一个DP的问题
leetcode longest consecutive sequence怎么做问个算法题2
leetcode longest consecutive sequence还是想不通!Ask a amazon question from careercup.
Interview street上的一题求助几道面试题
请教leetcode上的count and sayamazon phone interview
关于n个数的所有和的一个问题Random Array number, Find longest consecutive sequence
谁给个不是brute force的解法二爷的那个Longest Consecutive Sequence的新解法?
一道Google题请问leetcode 上那道Longest Consecutive Sequence题
相关话题的讨论汇总
话题: find话题: a1话题: idxup话题: idxdown话题: integers
进入JobHunting版参与讨论
1 (共1页)
S**Y
发帖数: 136
1
How do you find sequences of consequtive integers in a list that add to a pa
rticular number.
r****o
发帖数: 1950
2
看不懂,能说仔细一点吗?

pa

【在 S**Y 的大作中提到】
: How do you find sequences of consequtive integers in a list that add to a pa
: rticular number.

m*****f
发帖数: 1243
3
say a1, a2, a3, ....an:
compute the sum one by one and list them as a new list
a1, a1+a2, a1+a2+a3, a1+a2+a3+a4,.....,a1+....+an,
this will take O(n).
now the question becomes find two numbers a, b in this new list, that
a - b = that particular number, which is a typical 2sum problem solved
in O(n)
Possible follow-up: if the word "consequtive" is removed, then it becomes a
0/1 knapsack problem, could be solved by dp.
r****o
发帖数: 1950
4
能不能讲讲题目里面add to a particular number是啥意思?

a

【在 m*****f 的大作中提到】
: say a1, a2, a3, ....an:
: compute the sum one by one and list them as a new list
: a1, a1+a2, a1+a2+a3, a1+a2+a3+a4,.....,a1+....+an,
: this will take O(n).
: now the question becomes find two numbers a, b in this new list, that
: a - b = that particular number, which is a typical 2sum problem solved
: in O(n)
: Possible follow-up: if the word "consequtive" is removed, then it becomes a
: 0/1 knapsack problem, could be solved by dp.

m*****f
发帖数: 1243
5
sum = a particular number?

【在 r****o 的大作中提到】
: 能不能讲讲题目里面add to a particular number是啥意思?
:
: a

r****o
发帖数: 1950
6
呵呵,不好意思这才明白。

【在 m*****f 的大作中提到】
: sum = a particular number?
r****o
发帖数: 1950
7

这里是要考虑任意两个numbers吧,是不是O(n^2)?
a

【在 m*****f 的大作中提到】
: say a1, a2, a3, ....an:
: compute the sum one by one and list them as a new list
: a1, a1+a2, a1+a2+a3, a1+a2+a3+a4,.....,a1+....+an,
: this will take O(n).
: now the question becomes find two numbers a, b in this new list, that
: a - b = that particular number, which is a typical 2sum problem solved
: in O(n)
: Possible follow-up: if the word "consequtive" is removed, then it becomes a
: 0/1 knapsack problem, could be solved by dp.

m*****f
发帖数: 1243
8
hash table ah

【在 r****o 的大作中提到】
:
: 这里是要考虑任意两个numbers吧,是不是O(n^2)?
: a

r****o
发帖数: 1950
9
u r right

【在 m*****f 的大作中提到】
: hash table ah
S**Y
发帖数: 136
10
你理解错题意了吧
题目是说,consecutive的integers,不是连续的序号
比如:
2 4 7 3 10 4 8
那这个应该是7+8 = 15

a

【在 m*****f 的大作中提到】
: say a1, a2, a3, ....an:
: compute the sum one by one and list them as a new list
: a1, a1+a2, a1+a2+a3, a1+a2+a3+a4,.....,a1+....+an,
: this will take O(n).
: now the question becomes find two numbers a, b in this new list, that
: a - b = that particular number, which is a typical 2sum problem solved
: in O(n)
: Possible follow-up: if the word "consequtive" is removed, then it becomes a
: 0/1 knapsack problem, could be solved by dp.

相关主题
关于n个数的所有和的一个问题请教一个DP的问题
谁给个不是brute force的解法问个算法题2
一道Google题Ask a amazon question from careercup.
进入JobHunting版参与讨论
m*****f
发帖数: 1243
11
@@...then it's much more easier. just sort.

【在 S**Y 的大作中提到】
: 你理解错题意了吧
: 题目是说,consecutive的integers,不是连续的序号
: 比如:
: 2 4 7 3 10 4 8
: 那这个应该是7+8 = 15
:
: a

S**Y
发帖数: 136
12
if you sort you will lose the order
不再是 increasing的了

【在 m*****f 的大作中提到】
: @@...then it's much more easier. just sort.
m*****f
发帖数: 1243
13
en, 那我不会

【在 S**Y 的大作中提到】
: if you sort you will lose the order
: 不再是 increasing的了

r****o
发帖数: 1950
14
那不就是任意几个数的和等于15吗?
加法跟consecutive没关系吧?
0-1 knapsack?

【在 S**Y 的大作中提到】
: 你理解错题意了吧
: 题目是说,consecutive的integers,不是连续的序号
: 比如:
: 2 4 7 3 10 4 8
: 那这个应该是7+8 = 15
:
: a

h**k
发帖数: 3368
15
能详细讲讲么?怎么用hash table来做?

【在 m*****f 的大作中提到】
: hash table ah
k***e
发帖数: 556
16
哎 在问之前能否先阅读下基本的书籍。我在板上推荐programming pearls好几次了

pa

【在 S**Y 的大作中提到】
: How do you find sequences of consequtive integers in a list that add to a pa
: rticular number.

r****o
发帖数: 1950
17
programming peals哪章讲了这个问题啊

【在 k***e 的大作中提到】
: 哎 在问之前能否先阅读下基本的书籍。我在板上推荐programming pearls好几次了
:
: pa

k***e
发帖数: 556
18
这是一个习题

【在 r****o 的大作中提到】
: programming peals哪章讲了这个问题啊
H*M
发帖数: 1268
19
他也没看清楚题呵呵

【在 r****o 的大作中提到】
: programming peals哪章讲了这个问题啊
k***e
发帖数: 556
20
晕 这个楼主也不说清楚点
那个consecutive我还以为是说sequence contiguous
he should say find a subsequence in the array that is continuous increasing

【在 H*M 的大作中提到】
: 他也没看清楚题呵呵
相关主题
几道面试题二爷的那个Longest Consecutive Sequence的新解法?
amazon phone interview请问leetcode 上那道Longest Consecutive Sequence题
Random Array number, Find longest consecutive sequencezenefits店面(已挂)
进入JobHunting版参与讨论
k***e
发帖数: 556
21
ok, my fault
i misunderstand the problem
suppose the problem is: given an array of pos ints, find a subseqence (may
not be continuous in the idxes), that is continuous integers that sum to a
certain value)
1) for each a[i] in the array, find idxUp > i such that a[idxUp] = a[i] + 1
idxDown < i such that a[idxDown] = a[i] - 1, note that the idxUp is the one
who is closest to i (similar to find idxDown)
2) thus from any idx, we know where is the next a[idx]+1, now we need to get
the length of the c

【在 r****o 的大作中提到】
: programming peals哪章讲了这个问题啊
H*M
发帖数: 1268
22
yeah
max inreseacing sub sequence, max in terms of sum instead of lenth

increasing

【在 k***e 的大作中提到】
: 晕 这个楼主也不说清楚点
: 那个consecutive我还以为是说sequence contiguous
: he should say find a subsequence in the array that is continuous increasing

r****o
发帖数: 1950
23
没看明白,我怎么觉得这个问题就是0-1 knapsack啊?

1
one
get
=

【在 k***e 的大作中提到】
: ok, my fault
: i misunderstand the problem
: suppose the problem is: given an array of pos ints, find a subseqence (may
: not be continuous in the idxes), that is continuous integers that sum to a
: certain value)
: 1) for each a[i] in the array, find idxUp > i such that a[idxUp] = a[i] + 1
: idxDown < i such that a[idxDown] = a[i] - 1, note that the idxUp is the one
: who is closest to i (similar to find idxDown)
: 2) thus from any idx, we know where is the next a[idx]+1, now we need to get
: the length of the c

k***e
发帖数: 556
24
that can be solved in linear time instead of using dp

【在 r****o 的大作中提到】
: 没看明白,我怎么觉得这个问题就是0-1 knapsack啊?
:
: 1
: one
: get
: =

m******r
发帖数: 61
25
真难

pa

【在 S**Y 的大作中提到】
: How do you find sequences of consequtive integers in a list that add to a pa
: rticular number.

1 (共1页)
进入JobHunting版参与讨论
相关主题
请问leetcode 上那道Longest Consecutive Sequence题请教leetcode上的count and say
zenefits店面(已挂)关于n个数的所有和的一个问题
问个近来看到的狗家题:longest consecutive sequence in tree谁给个不是brute force的解法
问几道面试题一道Google题
Longest Consecutive Sequence 问题释疑请教一个DP的问题
leetcode longest consecutive sequence怎么做问个算法题2
leetcode longest consecutive sequence还是想不通!Ask a amazon question from careercup.
Interview street上的一题求助几道面试题
相关话题的讨论汇总
话题: find话题: a1话题: idxup话题: idxdown话题: integers