Interview Question






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

This is vague question. Besides the key, can we store nodes count in the tree nodes? If no more facilitation provided, no way to figure out the median in O(logn) IMHO.

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

question is not clear.
Anonymous please explain the question clearly with an example else don't put such junks.

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

As hunt said, we need to store count in nodes for O(logn) complexity.

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

This is perhaps not a vague question afterall... Its beauty is in its shortness.
Here's what I'd say, hopefully correct:

a = extract_min ( BST );
b = extract_max ( BST );
print "Median = ", sqrt(a*a + b*b), ", Mean = ", (a + b)/2.0;

What do you say?

- Nix September 22, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

That's Average Not median.

FYI: Median is Positional average of a list(sorted)

- Addy September 24, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

sqrt(a*a + b*b) is not the Median. See the definition of Median here

http://en.wikipedia.org/wiki/Median

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

median is also determined by the number of items in the list. if it is odd, then it would be the item in the middle else the average of two central items

- Anonymous September 27, 2009 | 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