由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 这题怎么做?
相关主题
问一道老题a[i] + b[j] = c[k] 的题有靠谱的答案不?
Google电话面试题目请教个面试题
这题怎么做?请教一个常见的面试题的答案
菜鸟问个two sum的变型题median of an array of ints, 请问这题的经典回答是什么?谢谢
[合集] Google电话面试题目求一下这题解法。
一个小公司面经这题也可以DP 解吧?
[算法] unsorted array请问这题是什么意思
讨论做题:find kth smallest number in two sorted arrays at终于弄明白median of two sorted arrays了,发帖庆祝一下
相关话题的讨论汇总
话题: alist话题: reverse话题: array话题: return话题: external
进入JobHunting版参与讨论
1 (共1页)
a*******y
发帖数: 1040
1
There is an external array of integers on which you can perform the
following operations in O(1) time.
1. get(int i) - returns the value at the index 'i' in the external array.
2. reverse( int i, int j) - returns the reverse of the array between index
positions i and j (including i and j).
example for reverse: consider an array {1,2,3,4,5}. reverse(0,2) will return
{3,2,1,4,5} and reverse(1,4) will return {1,5,4,3,2}.
Write a code to sort the external array. Mention the time and space
complexity for your code.
g****y
发帖数: 240
2
insertion sort? 不过要N^2的复杂度
def reverse(alist, i, j):
if i >= j:
return alist
return alist[:i] + alist[i: j + 1][::-1] + alist[j + 1:]


def sort(alist):
for i in range(1, len(alist)):
for j in range(i - 1, -1, -1):
if alist[j + 1] < alist[j]:
alist = reverse(alist, j, j + 1)
else:
break
return alist
A********l
发帖数: 184
3
冒泡排序? reverse(i, i+1) = swap(i, i+1)

return

【在 a*******y 的大作中提到】
: There is an external array of integers on which you can perform the
: following operations in O(1) time.
: 1. get(int i) - returns the value at the index 'i' in the external array.
: 2. reverse( int i, int j) - returns the reverse of the array between index
: positions i and j (including i and j).
: example for reverse: consider an array {1,2,3,4,5}. reverse(0,2) will return
: {3,2,1,4,5} and reverse(1,4) will return {1,5,4,3,2}.
: Write a code to sort the external array. Mention the time and space
: complexity for your code.

1 (共1页)
进入JobHunting版参与讨论
相关主题
终于弄明白median of two sorted arrays了,发帖庆祝一下[合集] Google电话面试题目
这题应该用bucket sort还是counting sort一个小公司面经
find medium number in stream 这题怎么作[算法] unsorted array
Median of Two Sorted Arrays这题真他妈的难讨论做题:find kth smallest number in two sorted arrays at
问一道老题a[i] + b[j] = c[k] 的题有靠谱的答案不?
Google电话面试题目请教个面试题
这题怎么做?请教一个常见的面试题的答案
菜鸟问个two sum的变型题median of an array of ints, 请问这题的经典回答是什么?谢谢
相关话题的讨论汇总
话题: alist话题: reverse话题: array话题: return话题: external