由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Check if the sum of two integers in an integer array eqauls to the given number
相关主题
问个面试题目An interview question. Thanks.
一FG家常见题 (转载)Re: amazon onsite interview question (转载)
[合集] 这个问题怎么解效率最高a probability interview question.
看一道面试题这个怎么allocate memory?
问一道面试题Java 的算法题:怎样把missing value替换成0 放在新生成的2D array里面?
[转载] CS Algorithm Interview question这两种写法面試时候你喜欢哪种?
讨论几个面试题贡献一下:本版上搜集的 Google 面试题 (转载)
If using C++, please avoid the use of STL for these questio (转载)3sum problem
相关话题的讨论汇总
话题: sum话题: array话题: integers话题: check话题: eqauls
进入Programming版参与讨论
1 (共1页)
z***e
发帖数: 14
1
I saw a similar post in this board, and recalled my recent interview
experience. Got this question in Amazon interview. Although I failed, it is
still a good one.
My answer:
1. Create a hash table to store all integers in this array. O(n)
2. For each int, look for sum - int in the created hash tree. Since hash
tree is the fastest look-up table, we can take advantage from it. n*O(1)
3. So this is O(n) algorithm.
Then the guy gave me the array 1, 2, 10, 20, sum is 2. My answer will return
true obv
o******r
发帖数: 259
2
What if you have a collision in setting up hash table.
Do you use list?
A simple solution is just count occurrence of a value.
Since it only needs to be checked when value == S/2,
the occurrence count doesn't affect much.

is
return

【在 z***e 的大作中提到】
: I saw a similar post in this board, and recalled my recent interview
: experience. Got this question in Amazon interview. Although I failed, it is
: still a good one.
: My answer:
: 1. Create a hash table to store all integers in this array. O(n)
: 2. For each int, look for sum - int in the created hash tree. Since hash
: tree is the fastest look-up table, we can take advantage from it. n*O(1)
: 3. So this is O(n) algorithm.
: Then the guy gave me the array 1, 2, 10, 20, sum is 2. My answer will return
: true obv

1 (共1页)
进入Programming版参与讨论
相关主题
3sum problem问一道面试题
INTEGER搜索求建议[转载] CS Algorithm Interview question
一个哈希表问题讨论几个面试题
面试题 -算法?If using C++, please avoid the use of STL for these questio (转载)
问个面试题目An interview question. Thanks.
一FG家常见题 (转载)Re: amazon onsite interview question (转载)
[合集] 这个问题怎么解效率最高a probability interview question.
看一道面试题这个怎么allocate memory?
相关话题的讨论汇总
话题: sum话题: array话题: integers话题: check话题: eqauls