由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 一道面试题
相关主题
这个用stack实现queuefunction pointer 是compile time还是run time得到地址的?
CareerCup question【分享】最新出炉的微软面试题
还有两个题。一个facebook面试题
对一些烂大街了的面试题, 要注意伪装Google的电话面试题
share 面试题求助一个面试题
问个经典面试题用C设计Stack的interface,要求支持各种数据类型。
面试题题目: iterative binary tree post order traversal
一道很难的面试题请教两道算法题
相关话题的讨论汇总
话题: stack话题: max话题: pop话题: push话题: return
进入JobHunting版参与讨论
1 (共1页)
h****y
发帖数: 21
1
special stack, besides push/pop, can return the max number in the stack
the point is that all the performance of the three functions should be O(1)
Thank you for discussing
c*****r
发帖数: 1491
2

use two stack
one for keeping the max

【在 h****y 的大作中提到】
: special stack, besides push/pop, can return the max number in the stack
: the point is that all the performance of the three functions should be O(1)
: Thank you for discussing

h****y
发帖数: 21
3
could you explaine the details?
notice that all the three function should be O(1)

【在 c*****r 的大作中提到】
:
: use two stack
: one for keeping the max

h****y
发帖数: 21
4
I've got it. Thank you:)
the second array is the sorted one to store pointers which can be pushed and
poped at the same time with the first stack, right?

【在 c*****r 的大作中提到】
:
: use two stack
: one for keeping the max

h****y
发帖数: 21
5
Also, the second array should be the double link list

and

【在 h****y 的大作中提到】
: I've got it. Thank you:)
: the second array is the sorted one to store pointers which can be pushed and
: poped at the same time with the first stack, right?

z****e
发帖数: 2024
6
two regular stack S1, S2.
for the special stack:
push(a){
S1.push(a);
max=S2.top();
S2.push(a>max?a:max);
}
pop(){
S1.pop();
S2.pop();
}
max(){
return S2.top();
}
top(){
return S1.top();
}
g*******y
发帖数: 1930
7
for second stack, ith element record the max among 1st~ith element.

【在 h****y 的大作中提到】
: Also, the second array should be the double link list
:
: and

h****y
发帖数: 21
8
You are right , the sort algorithm can't be done in O(1)
we need another way.

one
z****e
发帖数: 2024
9
anything wrong with my algorithm?
thank you in advance.
h****y
发帖数: 21
10
this is the problem I got from this morning's amazon phone interview.
Do you think it's possible the interviewer ask an unsolvable question?
相关主题
问个经典面试题function pointer 是compile time还是run time得到地址的?
面试题【分享】最新出炉的微软面试题
一道很难的面试题一个facebook面试题
进入JobHunting版参与讨论
z****e
发帖数: 2024
11
did you use the same method as mine?

【在 h****y 的大作中提到】
: this is the problem I got from this morning's amazon phone interview.
: Do you think it's possible the interviewer ask an unsolvable question?

z****e
发帖数: 2024
12
这个题目充分说明了,算法的面试,是没有办法准备的。

【在 h****y 的大作中提到】
: this is the problem I got from this morning's amazon phone interview.
: Do you think it's possible the interviewer ask an unsolvable question?

h****y
发帖数: 21
13
No, I think there is problem with your pop function
you need to keep the S1 and S2 pop the same element
My answer in the interview only can meet push O(1), pop O(n), max O(1)
by save and update the max element in the extra pointer

【在 z****e 的大作中提到】
: did you use the same method as mine?
h****y
发帖数: 21
14
that make sense. I've never think the interviewer's question can be
unsolvable before.
Next time, I will try to challenge them more:)
h****y
发帖数: 21
15
it looks correct!
thank you so much:)

【在 z****e 的大作中提到】
: 这个题目充分说明了,算法的面试,是没有办法准备的。
z****e
发帖数: 2024
16
Actually, this reminds me that there is another problem saying:
use two stacks to maintain a queue, for Dequeue() and Enqueue(a) operation
with amortize O(1).
p*********a
发帖数: 21
17
第二个stack用单调队列,只push和pop最大值, 空间上会更节省。
1 (共1页)
进入JobHunting版参与讨论
相关主题
请教两道算法题share 面试题
一道刚面的算法题问个经典面试题
问个google面试题面试题
问一下STL里的queue, and stack 遍历的问题一道很难的面试题
这个用stack实现queuefunction pointer 是compile time还是run time得到地址的?
CareerCup question【分享】最新出炉的微软面试题
还有两个题。一个facebook面试题
对一些烂大街了的面试题, 要注意伪装Google的电话面试题
相关话题的讨论汇总
话题: stack话题: max话题: pop话题: push话题: return