由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - amazon 电面题
相关主题
问大家关于编程的经验问一道CareerCup里的题目
请教一道题目再问一个算法题。
问题:Find the minimum number of "swaps" needed to sort an array1G内存读10G文件
Find the Kth smallest element in 2 sorted把leetcode做完了
write a c++ code for rotated sorted arraylc新题,贴个刚写的solution
binary search in rotated sorted array有重复时怎么办?Leetcode上面的"Search in rotated sorted array II"
这个rotated sorted array问题有没有人总结过binary search是mid加减1和小于或者等于的情况分类
问个rotated array里面找element的问题G家onsite面经,求bless,顺便问问这情况能有戏吗
相关话题的讨论汇总
话题: arr话题: smallest话题: rotated话题: array话题: int
进入JobHunting版参与讨论
1 (共1页)
b******y
发帖数: 126
1
A sorted array is rotated(rotate position is unknown), find the index for
the smallest element.
Example: 1 2 3 4 5 6 7, after rotated to the right becomes 4 5 6 7 1 2 3
a*****y
发帖数: 467
2
每次比较中间和两头的值吧
跟rotated array的二分查找类似

【在 b******y 的大作中提到】
: A sorted array is rotated(rotate position is unknown), find the index for
: the smallest element.
: Example: 1 2 3 4 5 6 7, after rotated to the right becomes 4 5 6 7 1 2 3

B*****g
发帖数: 193
3
怎么知道中间?
One stupid algorithm I can think of:
int smallestIndex(int arr[], int size)
{
int smallest = arr[0];
int index = 0;
for( int i = 1; i < size; ++i ){
if( arr[i] < arr[i-1] && smallest > arr[i] ){
smallest = arr[i];
index = i;
}
}
return index;
}

【在 a*****y 的大作中提到】
: 每次比较中间和两头的值吧
: 跟rotated array的二分查找类似

c**********e
发帖数: 2007
4
The trick of the question is that, in the worst scenario, the approach can
only be O(n). If the array has all a[i]=1, you have to go through every
element. If you do not, one of it (if only one of it) could be 0. But for
general case, it should be O(logn) (the binary search approach).
With that the approach is clear. Use recursion. For an array a[i] to a[j]
with i )/2 or k=(i+j+1)/2. If a[k]>a[j], then call the subroutine for

【在 b******y 的大作中提到】
: A sorted array is rotated(rotate position is unknown), find the index for
: the smallest element.
: Example: 1 2 3 4 5 6 7, after rotated to the right becomes 4 5 6 7 1 2 3

w******y
发帖数: 519
5
only rotate once??
1 (共1页)
进入JobHunting版参与讨论
相关主题
G家onsite面经,求bless,顺便问问这情况能有戏吗write a c++ code for rotated sorted array
MS Onsite面经binary search in rotated sorted array有重复时怎么办?
Rotating an array in place这个rotated sorted array问题
小结可以应用二分查找的面试题问个rotated array里面找element的问题
问大家关于编程的经验问一道CareerCup里的题目
请教一道题目再问一个算法题。
问题:Find the minimum number of "swaps" needed to sort an array1G内存读10G文件
Find the Kth smallest element in 2 sorted把leetcode做完了
相关话题的讨论汇总
话题: arr话题: smallest话题: rotated话题: array话题: int