由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Get first Greater in a array
相关主题
何解啊.....请教个面经里的设计题
Implement an web-based dictionary lookup请教一个面试题
merge k个数组怎样的方法好?请教一道数据结构的设计题
两个面试题一个关于hash table的interview question
amazon 电面面经顶风作案,贡献一道最近onsite的原题
Phone Interview面经Google电面
amazon intern 3电问道题,谁给个效率高点的解法
面试被拒,百思不得其解,求指点最近连着几个面试都是印度人。
相关话题的讨论汇总
话题: idx话题: int话题: val话题: array话题: amortized
进入JobHunting版参与讨论
1 (共1页)
s******e
发帖数: 108
1
Implement an array on ints which supports
1) void lookup(int idx) : value stored at idx, in amortized O(1) time.
2) void append(int value) : adds a value at the end of the array, in
amortized
O(1) time.
3) void set(int idx, int val) : sets the value at idx to val. if idx >
length
, throws an error. Complexity amortized O(1) time.
4) int GetFirstMaxIndex(int val): Gets the first index such that the element
at the idx is > val. Complexity O(logn).
ex [2, 10,5,6,80]
input : 6 output : 10
input :20 output : 80
l*****a
发帖数: 14598
2
ArrayList for the first 3 requirements
for the 4th, create a new array as 2,10,10,10,80 and then u can get it

element

【在 s******e 的大作中提到】
: Implement an array on ints which supports
: 1) void lookup(int idx) : value stored at idx, in amortized O(1) time.
: 2) void append(int value) : adds a value at the end of the array, in
: amortized
: O(1) time.
: 3) void set(int idx, int val) : sets the value at idx to val. if idx >
: length
: , throws an error. Complexity amortized O(1) time.
: 4) int GetFirstMaxIndex(int val): Gets the first index such that the element
: at the idx is > val. Complexity O(logn).

g**e
发帖数: 6127
3
array list append不是每次都是O(1)吧

【在 l*****a 的大作中提到】
: ArrayList for the first 3 requirements
: for the 4th, create a new array as 2,10,10,10,80 and then u can get it
:
: element

c*****n
发帖数: 96
4
then what's the time complexity for set(0, 100) operation using the example
given by LZ ?

【在 l*****a 的大作中提到】
: ArrayList for the first 3 requirements
: for the 4th, create a new array as 2,10,10,10,80 and then u can get it
:
: element

l*****a
发帖数: 14598
5
http://docs.oracle.com/javase/6/docs/api/
The add operation runs in amortized constant time, that is, adding n
elements requires O(n) time.

【在 g**e 的大作中提到】
: array list append不是每次都是O(1)吧
l*****a
发帖数: 559
6
感觉1)2)3)成立的情况下,4)无法实现。
w*******y
发帖数: 85
7

nice.

【在 l*****a 的大作中提到】
: ArrayList for the first 3 requirements
: for the 4th, create a new array as 2,10,10,10,80 and then u can get it
:
: element

f*****e
发帖数: 2992
8
add a fake value to every element:
fake(a[i+1])=max{fake(a[i]), a[i+1]}
binary search val among fake(a[1...n])

element

【在 s******e 的大作中提到】
: Implement an array on ints which supports
: 1) void lookup(int idx) : value stored at idx, in amortized O(1) time.
: 2) void append(int value) : adds a value at the end of the array, in
: amortized
: O(1) time.
: 3) void set(int idx, int val) : sets the value at idx to val. if idx >
: length
: , throws an error. Complexity amortized O(1) time.
: 4) int GetFirstMaxIndex(int val): Gets the first index such that the element
: at the idx is > val. Complexity O(logn).

z****x
发帖数: 25
9
what about set() operation?

【在 f*****e 的大作中提到】
: add a fake value to every element:
: fake(a[i+1])=max{fake(a[i]), a[i+1]}
: binary search val among fake(a[1...n])
:
: element

1 (共1页)
进入JobHunting版参与讨论
相关主题
最近连着几个面试都是印度人。amazon 电面面经
lc perfect squres的time complexity是多少Phone Interview面经
[合集] 一道Google面试题amazon intern 3电
一道微软面试题面试被拒,百思不得其解,求指点
何解啊.....请教个面经里的设计题
Implement an web-based dictionary lookup请教一个面试题
merge k个数组怎样的方法好?请教一道数据结构的设计题
两个面试题一个关于hash table的interview question
相关话题的讨论汇总
话题: idx话题: int话题: val话题: array话题: amortized