由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 给定一个值和sorted队列,只有唯一的pair其和等于给定值
相关主题
给定一个值和sorted队列,找到所有pair(其和等于给定值)请教一道题
[算法] unsorted array请问一个老的google题
a[i] + b[j] = c[k] 的题有靠谱的答案不?请教一道面试题
我再说说我挂掉的那道题吧请教一个老算法题, k-th largest sum
问一个给定的array 和一个sum value,找最小sub-array,谢谢longest subarray with numbers arranged as a seq
Amazon二面结束,求BLESS[emc/greenplum面试]senior engineer
一个精华区的算法题FB电面
amazon tel interviewleetcode: Remove Duplicates from Sorted Array
相关话题的讨论汇总
话题: target话题: search话题: array话题: find话题: 给定
进入JobHunting版参与讨论
1 (共1页)
y***e
发帖数: 32
1
如何找到这个pair,有O(log n)的解法吗?
Sorted的队列包含duplicate元素.
h***t
发帖数: 2540
2
Yes, binary search, compare 2* arr[mid] with target, then move left or
right, which depends.

【在 y***e 的大作中提到】
: 如何找到这个pair,有O(log n)的解法吗?
: Sorted的队列包含duplicate元素.

y***e
发帖数: 32
3
请问能详细介绍一下。
多谢!

【在 h***t 的大作中提到】
: Yes, binary search, compare 2* arr[mid] with target, then move left or
: right, which depends.

m********6
发帖数: 58
4
How does that work? He is trying to find duplicates. If medium in array a is
10 and medium in array b is 8. How do you move? You know there is no
overlap between right side of array 1(>10) and left side of array b (<8).
You can not infer anything about the other subsets.

Yes, binary search, compare

【在 h***t 的大作中提到】
: Yes, binary search, compare 2* arr[mid] with target, then move left or
: right, which depends.

m********6
发帖数: 58
5
I don't think there is a solution better than O(N) where N is the combined
length of the two arrays. I wasn't able to find a better solution online
either.

How does that work? He is trying to find duplicates. If medium in array a is
10 and medi........

【在 m********6 的大作中提到】
: How does that work? He is trying to find duplicates. If medium in array a is
: 10 and medium in array b is 8. How do you move? You know there is no
: overlap between right side of array 1(>10) and left side of array b (<8).
: You can not infer anything about the other subsets.
:
: Yes, binary search, compare

y***e
发帖数: 32
6
Following hjdut's suggestion, I figured out a O(log n) solution to find a
pair of elements whose sum is equal to the given target.
1. Search for the target in {A[i] + A[i + 1], i = 0, ..., n - 2}
2. If the target is not found in step 1, find i such that A[i - 1] + A[i] <
target < A[i] + A[i + 1].
3. Start from this A[i] + A[i + 1] to explore the given target either
upwards or rightwards in the matrix {m[i,j] = A[i] + A[j]}. Here the
exploring process can be done in binary search way as well, which leads to
the O(log n) solution.

【在 h***t 的大作中提到】
: Yes, binary search, compare 2* arr[mid] with target, then move left or
: right, which depends.

1 (共1页)
进入JobHunting版参与讨论
相关主题
leetcode: Remove Duplicates from Sorted Array问一个给定的array 和一个sum value,找最小sub-array,谢谢
今天计划做20题Amazon二面结束,求BLESS
小公司onsite面经(求bless)一个精华区的算法题
Google电话面试题目amazon tel interview
给定一个值和sorted队列,找到所有pair(其和等于给定值)请教一道题
[算法] unsorted array请问一个老的google题
a[i] + b[j] = c[k] 的题有靠谱的答案不?请教一道面试题
我再说说我挂掉的那道题吧请教一个老算法题, k-th largest sum
相关话题的讨论汇总
话题: target话题: search话题: array话题: find话题: 给定