boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 也问两个算法题
相关主题
[合集] M$ interview question
[合集] 【讨论】两道非常难的Google面试题
Polish Notation
Groupon一个店面题. sort with 3 stacks.
还有两个题。
一个stack怎么sort
判断一个linked list是不是palindrome
G电面
面试时候C++ pop之前是空 大家怎么处理。。返回什么。。 假设stack 元素都是int形的。
一小段程序,请诸位牛帮忙找下bug,谢谢!
相关话题的讨论汇总
话题: stack话题: sortstack话题: newx话题: sort话题: call
进入JobHunting版参与讨论
1 (共1页)
g*******y
发帖数: 1930
1
1. sort stack using only pop(), top(), push(), isEmpty(),isFull(). Do not
use any auxiliary stacks or arrays.
感觉不用辅助空间做不到啊,这题是真的有很巧妙的方法?还是玩玩文字游戏--比如用
linked list然后宣称它不是stack也不是array...
2. Given a set of coin denominators, find the minimum number of coins to
give a certain amount of change
贪心和DP,回溯法应该都能做的,无非就是状态空间搜索,但是我想到的都是伪多项式
的算法,感觉这道题应该能利用某些数论的知识在多项式时间解决?
k*k
发帖数: 49
2
1. sort stack using only pop(), top(), push(), isEmpty(),isFull(). Do not
use any auxiliary stacks or arrays.
use the function call stack for temporary storage... O(n^2) i guess.
你想多了。。。 :)
a*****e
发帖数: 51
3
1. Yes you can do it, if you can use system stack.

【在 g*******y 的大作中提到】
: 1. sort stack using only pop(), top(), push(), isEmpty(),isFull(). Do not
: use any auxiliary stacks or arrays.
: 感觉不用辅助空间做不到啊,这题是真的有很巧妙的方法?还是玩玩文字游戏--比如用
: linked list然后宣称它不是stack也不是array...
: 2. Given a set of coin denominators, find the minimum number of coins to
: give a certain amount of change
: 贪心和DP,回溯法应该都能做的,无非就是状态空间搜索,但是我想到的都是伪多项式
: 的算法,感觉这道题应该能利用某些数论的知识在多项式时间解决?

t********e
发帖数: 25
4
Bubble sort recursively?
SortStack(stack s)
{
if s.notEmpty()
{
x = s.pop();
if( x < s.top() )
{ newx = s.pop() ;
s.push(x);
x = newx;
}
SortStack(s);
s.push(x);
}
}
Call this n times.
1 (共1页)
进入JobHunting版参与讨论
相关主题
一小段程序,请诸位牛帮忙找下bug,谢谢!
Interview question::
问一个题
悲剧的FB二面
请教两道算法题
问个G家面经题
amazon intern一共几面, 加面经
怎么提高BST traversal efficiency?
recursive中该用reference 还是普通变量传递?
今天的面试。。。
相关话题的讨论汇总
话题: stack话题: sortstack话题: newx话题: sort话题: call