I was somewhat pained by this, as this is an interview question I've gotten, and I clearly annoyed the interviewer by knowing this isn't true, and you can avoid a full sort (which, at least two others have noted).
A software engineering interview question I like: computing the median
51–60 of 97 posts
Re: A software engineering interview question I like: computing the median
#52Earlier quoted context omitted.
So for about 10 years my main interview question was: "Write me a function in any language of your choosing, that takes an array of integers and returns the sum." I loved it. Here is why: 1. I'd get to see them write code, in a low pressure way, but they'd have to write something 2. A shocking number of people would struggle to write the code. That was my signal to end the interview early. 3. I'd get to ask "So tell…
Interesting approach. Thanks for sharing. I should send my students your way for internships!
Re: A software engineering interview question I like: computing the median
#53Huh, feels overly simple to me. How about something like the beginnings of a spreadsheet engine? Or.. count the number of distinctly shaped black regions in a bitmap image.
So for about 10 years my main interview question was: "Write me a function in any language of your choosing, that takes an array of integers and returns the sum." I loved it. Here is why: 1. I'd get to see them write code, in a low pressure way, but they'd have to write something 2. A shocking number of people would struggle to write the code. That was my signal to end the interview early. 3. I'd get to ask "So tell…
Re: A software engineering interview question I like: computing the median
#54if you are not aware of quickselect algorithm.
Re: A software engineering interview question I like: computing the median
#55Earlier quoted context omitted.
So for about 10 years my main interview question was: "Write me a function in any language of your choosing, that takes an array of integers and returns the sum." I loved it. Here is why: 1. I'd get to see them write code, in a low pressure way, but they'd have to write something 2. A shocking number of people would struggle to write the code. That was my signal to end the interview early. 3. I'd get to ask "So tell…
Interesting approach, thanks. Yeah, I don't mind a question and conversation like that to start things off. But I do think getting into something a little deeper (which you also mentioned) later in the interview is important, too.
I'm not sure if its best to focus on strengths of weaknesses, but i did prefer to focus on strengths. I found convincing myself why I do want to work with someone was a better experience than trying to find reasons not to. Also it just tended to get better buy in from the other team member that way, and i'd know how to assign work once they joined.
Re: A software engineering interview question I like: computing the median
#56I don't know... I've been coding for ~30 years, and I've never had to write code to compute the median so it doesn't seem that useful unless it's somehow relevant to the job
> ... I've never had to write code to compute the median so it doesn't seem that useful unless it's somehow relevant to the job A binary search[0] of a sorted collection requires the median of each region being considered for each iteration. 0 - https://en.wikipedia.org/wiki/Binary_search
Re: A software engineering interview question I like: computing the median
#57Honestly, when I ran this interview I didn’t care much about the specifics of what you memorized beforehand. I care if you can read and write code a bit. I care more whether we can have a productive conversation. If you learn something new from me or the problem, how does that look and feel? If I make a mistake, how do you react? Are we able to communicate technical ideas to each other? Are we able to productively work through conflict?
We’re not computing many medians day-to-day, but we’re doing all those other things constantly.
Re: A software engineering interview question I like: computing the median
#58Earlier quoted context omitted.
How does one determine the median wherein "the other numbers can be unsorted"? To wit, given the unordered set: [ 5, 1, 3 ] How would "Only the median (or pair around the median) needs to be sorted" be satisfied?
https://en.wikipedia.org/wiki/Quickselect
As with quicksort, quickselect is generally implemented as
an in-place algorithm, and beyond selecting the kth
element, it also partially sorts the data.
When the above is applicable, those quickselect implementations would violate the original assertion of: Only the median (or pair around the median) needs to be
sorted, the other numbers can be unsorted
When the collection involved is immutable.Re: A software engineering interview question I like: computing the median
#59Earlier quoted context omitted.
> ... I've never had to write code to compute the median so it doesn't seem that useful unless it's somehow relevant to the job A binary search[0] of a sorted collection requires the median of each region being considered for each iteration. 0 - https://en.wikipedia.org/wiki/Binary_search
Not picking on you but your answer prove the parent comment's point. Your answer is that of someone that googled some answer and went with it. This problem belongs to selection algorithms and quickselect is the common approach.
My answer was one from experience and supported by a resource which provides details as to why medians are needed in real-world scenarios.
> This problem belongs to selection algorithms and quickselect is the common approach.
I responded to a specific comment in this discussion, not to what "this problem belongs."
Re: A software engineering interview question I like: computing the median
#60Huh, feels overly simple to me. How about something like the beginnings of a spreadsheet engine? Or.. count the number of distinctly shaped black regions in a bitmap image.
So for about 10 years my main interview question was: "Write me a function in any language of your choosing, that takes an array of integers and returns the sum." I loved it. Here is why: 1. I'd get to see them write code, in a low pressure way, but they'd have to write something 2. A shocking number of people would struggle to write the code. That was my signal to end the interview early. 3. I'd get to ask "So tell…