Bazaarvoice Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

bfs or dfs, but keeping track of the current level - dont go past level x and only print items at level x.

- anon September 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

b_level(root,k)
{
if(k==0)
printf(root->value)
else
{
b_level(root->left,k-1);
k--;
b_level(root->right,k);
}
}

int main()
{
for(k=0,k<h;k++) //h is hgt of tree
{
b_level(root,k);
}
return;
}

this is the code given in NI paper on 14 sep in NITK, surathkal
they asked to find what code is doing.. it is printing all nodes at kth level. you can trace.

- varun.friendly September 29, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Wouldn't it actually print all the nodes UP TO the kth level? That is what the for loop is doing.

- Anonymous September 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about this approach::

Root Level to begin with is 0. And 'desired' level is depth at which we wish to
print the node values

printAtDesiredLevel(node *root,int level,int desired)
{
if(!root)return
else if(level==desired)
{
printf("%d",root->value)
return
}
printAtDesiredLevel(root->left,level+1,desired)
printAtDesiredLevel(root->right,level+1,desired)
}

void main()
{
printAtDesiredLevel(root,0,<desiredLevelValue>)
}

- amit October 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You algorithm for printing a level is equivalent to the earlier one copied from NI. Your main() is the correct solution to the original problem, since it prints ONLY the desired level, whereas the NI main() prints all the levels UP TO (and including) the level specified.

Couldn't you optimize your algorithm by doing a level++ once before the left/right traversal, or even ++level in the left traversal? Just think how many clock cycles it would save!! Just kidding, I have a disease that makes me spot these things.

It might make it a bit more readable, although yours is already much more readable compared to the NI code that uses k-1 in the left traversal, then decrements (k--), then uses k (now decremented) in the right traversal.

- Anonymous September 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

bfs without recursion using a queue...
that way when you reach the level (x-1) ,[x is the required level], you can simply add the next left and right nodes to any desired data structure thus saving one step of actually traversing to the required level..

- Mihir July 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am an IT Recruiter looking for some Software Engineers in the Austin area contact me directly--client has asked that I recruit specifically for Bazaarvoice candidates suzie.jimenez@thehtgroup.com 512.345.9300

- suziejimenez3 September 25, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More