Remix.run Logo
ta93754829 2 days ago

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

oreally a day ago | parent | next [-]

Psychologists have been saying for ages that a good job interview is a small version of what the job requires them to do. But as always with most professions with people (and hence ego) involved, these people either mimic what the trending company in their sector does or test irrelevant academia knowledge.

Maybe for such changes to happen the whole profession to go down a notch in prestige. Not sure if people can stomach that.

looking-for-job a day ago | parent [-]

[dead]

Induane 2 days ago | parent | prev | next [-]

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.

bigiain 2 days ago | parent [-]

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 requirements, I'll just reach for the simplest possible solution, which for me would be something like cat textfile | tr ' ' '\n' | sort | uniq -c | sort -r That doesn't handle punctuation, probably doesn't handle unicode the way you might expect, and has a bunch of other things that additional requirements might rule out. But that'd be my starting point."

Induane 2 days ago | parent [-]

That's a good solution using existing tools, but I usually want it solved in whatever programming language is being tested. Not because command line tools aren't often an underutilized solution but because I am looking for their tendencies. Do they reach for a hashmap? Can they calculate it all in one pass? That kind of thing.

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' < textfile | sort | uniq -c | sort -r

Or even:

< textfile tr ' ' '\n' | sort | uniq -c | sort -r

bigiain a day ago | parent [-]

Yeah - I think we're on the same page here?

If I'm interviewing at a Python shop that actually does statistics t=ype stuff or text munging, I'd expect them to have preferred/existing solutions for these tasks in their standard dependencies. And if it were a Javascript/Nodejs shop, or a C/C++ shop, or a Rust shop, they'd also have "standard tooling" that'd be "the preferred option" to anything I could hand roll (either in an interview or during a regular workday).

My "sort | uniq | sort" pipeline (usually combined with grep/tr/awk/sed or similar) is a reasonable answer for an underspecified task with none of the obviously existing but as yet unstated requirements that'd come along with this task is "the real world". It's not an actual proposed piece of production code - it's a way to demonstrate "a" way of doing it without even committing to a language, never mind whatever is in the in house standard set of modules.

If you want to test how find the median in Python, my immediate question would be "what Python modules are you already using? It'd be foolish to invent it myself if the actual codebase already imports numpy or pandas or SciPy. And it's be equally foolish to import one of those if they are already not in use.

(Admittedly, it's been a _looooong_ time since I interviewed for a junior or mid level developer role where leetcode games might be part of the hiring hoop-jumping.)

Traster a day ago | parent | prev | next [-]

I'm not certain the point of an interview is to ask you to write the exact lines of code that you would write during the job.

AdieuToLogic 2 days ago | parent | prev [-]

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

halayli 2 days ago | parent [-]

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.

AdieuToLogic 2 days ago | parent [-]

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