Live data from Hacker News

A software engineering interview question I like: computing the median

krisshamloo.com

51–60 of 97 posts

Re: A software engineering interview question I like: computing the median

#51
> Right out the gate: the numbers must be sorted.

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).

https://en.wikipedia.org/wiki/Quickselect

Re: A software engineering interview question I like: computing the median

#52
post #50
post #35

Earlier 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!

ha, i'd have loved that. I'm out of the world where I hire people these days, solo founder life. Maybe i'll go back there, but it's a real mission objective to just be a one man show right now.

Re: A software engineering interview question I like: computing the median

#53
post #35

Huh, 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…

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.

Re: A software engineering interview question I like: computing the median

#55
post #35

Earlier 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.

For sure. I mean, i think naturally you'll end up there if all goes well. Have some tricky questions prepared of course, but starting simple gives you so much so quickly and often tells you where their strengths and weaknesses will end up being.

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

#56

I 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

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.

Re: A software engineering interview question I like: computing the median

#57
We used to use this, but it was a broader conversation around tradeoffs to meet different constraints. If the expected array is small, then sort + index is probably fine. If it’s big (bigger than main memory?) and latency is the most important then maybe you want median-of-medians. If it’s a stream and you want to keep memory fixed then you might want a sketching algorithm. If I suggest that we can bound the error of the median estimate with constant additional space and the same complexity, would you believe me? (Just track the mean and standard deviation.)

Honestly, 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

#58

Earlier 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

From the Wikipedia page cited:

  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

#59
post #56

Earlier 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.

> Your answer is that of someone that googled some answer and went with it.

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

#60
post #35

Huh, 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…

I used to do phone screens with a similarly simple question. I am still blown away that something like 60% would fail to write working code. I had more parts for the 40% that got it the first one, but it was crazy how many people couldn't do the most trivial task.
Post reply on HN