> Right out the gate: the numbers must be sorted. But they don't. I hope you, as an interviewer, have the grace to learn when one of your interviewees points out your mistake. :-) Median is O(n), not nlogn
A software engineering interview question I like: computing the median
71–80 of 97 posts
Re: A software engineering interview question I like: computing the median
#72Re: A software engineering interview question I like: computing the median
#73Earlier quoted context omitted.
One interview question I like that's simpler and more applicable is to code a function that outputs the frequency count of each word in a string of text. Bonus for outputting the count in most to least order.
Is that really a "more applicable" task that finding the median? Are there actually software development jobs where either of those tasks are a regular/common part of the work, where people don't "just know" how to do them using whatever tools the job already uses? I'm guessing I'd flunk your interview, because my initial response would be something like "No, I wouldn't write code for that. Unless there are unstated…
As for the why, it covers a class of issue that does come up; counting like items. Determining the frequency of things is pretty common. I run into variations on the problem a lot, even if word counting is a contrived example.
It also gives a good look at how someone might solve the "like" items - things like punctuation, casefolding, etc... - messing around with strings is something that happens all the time in the real world.
Also I might be tempted dock your shell solution for using cat unnecessarily
tr ' ' '\n' Or even:
< textfile tr ' ' '\n' | sort | uniq -c | sort -r
Re: A software engineering interview question I like: computing the median
#74This question, and many "but make it a bit more challenging!" comments always strike me as CS101 navelgazing type questions. The best part of this question is that it is simple and can be used to swing into deeper concerns but it is still at odds with actual job responsibilities - even more so with LLMs in the mix. Maybe this is because I have only worked at startups, but I am much more interested in if someone can r…
Re: A software engineering interview question I like: computing the median
#75I also like this question. A fun follow up is asking a candidate how to compute the 25th and 75th percentiles or more broadly, the n-th percentile.
I got that recently, I really didn't like that question. For the n-th percentile version, the obvious solution is sorting and it takes 10 seconds to get to that point, 5 minutes of implementation with tests. Good. It's all downhill from here. Then you get hit with the "it's a data stream" and you realize you have to implement a balanced tree on the spot which I wouldn't describe as fun. You may or may not be able to…
Re: A software engineering interview question I like: computing the median
#76Re: A software engineering interview question I like: computing the median
#77This question, and many "but make it a bit more challenging!" comments always strike me as CS101 navelgazing type questions. The best part of this question is that it is simple and can be used to swing into deeper concerns but it is still at odds with actual job responsibilities - even more so with LLMs in the mix. Maybe this is because I have only worked at startups, but I am much more interested in if someone can r…
One of those metrics is "number of people hired who literally can't write code". You'd be able to give these candidates a full description of what the median is and they still wouldn't be able to finish this question, and you're not going to get too many false positives, so you add it to your rotation as the first question and have an enthusiastic mid-level engineer do it as the first half-hour round of an interview.
Then you design a few more rounds to test for the positive things you want, like pair refactoring, architecture, lunch with the team, or whatever floats your boat. That way your senior engineers don't need to interview people who can't write code and you stand a lower chance of accidentally hiring some of them.
Re: A software engineering interview question I like: computing the median
#78In addition to the points listed, it gives the algorithm nerds the opportunity to show their overqualification by whipping out the O(n) median algorithm and proving that it works in linear time.
Or do a bucket sort on 32bit integers for worst case O(n) time, not O(n^2) Only half kidding… Using just 16GB RAM for a task is practically resource-constrained programming these days…
Later I felt stupid after reading about quick select.
Re: A software engineering interview question I like: computing the median
#79I 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
Maybe for such changes to happen the whole profession to go down a notch in prestige. Not sure if people can stomach that.
Re: A software engineering interview question I like: computing the median
#80After the candidate has finished this, you could then ask them to compute the weighted median. Chances are, the candidate has never heard of this term and yet the term is simple enough that without prior knowledge they can use their intuition to give a definition for this term and implement it. Good candidates can define and implement it for weights that are natural numbers, and better candidates can implement it for…
How do you know they didn't just have heard about weighed median before and how to implement it? Or did just more grinding on leetcode in general. I am not convinced that what you call "strong" can be tested by something like that.