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.

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.

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.

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?

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

That's Average Not median.

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

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

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

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.

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.