avatar
m*m
1
Interview Questions:
1.Given a node in a binary tree find the next greatest value in the entire
node.
2.Given a string with only ')' and '(' find if the string is complete or
not. If the string is complete means that each open paranthesis should have
a corresponding closed one.
Eg: String s= "((()))()"- Complete String
String s1=")()()()())))(()()()((" - Incomplete String
avatar
r*b
2
Do not understand the first question well. Any explanation?
Here is my answer to the second question:
http://basicalgos.blogspot.com/2012/03/19-testing-whether-strin
Please give out comments.

entire
have

【在 m*******m 的大作中提到】
: Interview Questions:
: 1.Given a node in a binary tree find the next greatest value in the entire
: node.
: 2.Given a string with only ')' and '(' find if the string is complete or
: not. If the string is complete means that each open paranthesis should have
: a corresponding closed one.
: Eg: String s= "((()))()"- Complete String
: String s1=")()()()())))(()()()((" - Incomplete String

avatar
P*U
3
The first one is BST or just binary tree? What do you mean by the next
greatest value? Is it the second largest value?
If BST and next means second largest, then easy.
Node* p=givenNode;
if(p->rightChild==null)
return FindLargestInLeftSubtree();
while(p->rightChild->rightChild!=null)
p=p->rightChild;
return p;
If not BST, you have to traverse the tree?
The second one can be solved with a stack. Once seen a "(", push into
stack;
seen a ")", pop. If the stack is empty when operating pop, return false.
When processed all symbols in the string, if the stack is not empty,
return
false, else return true.
avatar
m*m
4
The first question, I guess it is a binary search tree? And does each node
have a parent pointer?
for BST : get the node and find the inorder successor
if(n->right) : find minimum in n->right
else
find parent of n in loop, till n is parent->right :
(n = parent, find parent(n)
avatar
r*b
5
As for the second question, a counter should be sufficient. The stack is
not needed.
http://basicalgos.blogspot.com/2012/03/19-testing-whether-strin

【在 P*******U 的大作中提到】
: The first one is BST or just binary tree? What do you mean by the next
: greatest value? Is it the second largest value?
: If BST and next means second largest, then easy.
: Node* p=givenNode;
: if(p->rightChild==null)
: return FindLargestInLeftSubtree();
: while(p->rightChild->rightChild!=null)
: p=p->rightChild;
: return p;
: If not BST, you have to traverse the tree?

avatar
m*6
6
1-没大看明白
2- stack
在 musicworm (云淡了风轻) 的大作中提到: 】
entire
~~~~~tree??
have
avatar
a*a
7
1.BST
2.one counter should be enough

【在 m******6 的大作中提到】
: 1-没大看明白
: 2- stack
: 在 musicworm (云淡了风轻) 的大作中提到: 】
: entire
: ~~~~~tree??
: have

avatar
m*6
8

2.one counter should be enough ~~good!

【在 a****a 的大作中提到】
: 1.BST
: 2.one counter should be enough

avatar
m*m
9
another question:
what are the Google products?
avatar
y*n
10
1就是找floor吧。上数据结构的时候讲过- -
avatar
m*k
11
for Q2:
int sum=0;
for (char c in yourString)
{
if(c=='(')
{
sum++;
}
else
{
sum--;
}
if(sum<0)
{
return "invalid";
}
}
if(sum!=0)
{
return "invalid";
}
return "valid";
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。