frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

A software engineering interview question I like: computing the median

https://krisshamloo.com/blog/007
42•speckx•1h ago

Comments

apricot•1h ago
In 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.
salamanderman•57m ago
I almost tanked an interview, and luckily turned it around, when the interviewer had never heard of QuickSelect and thought I was insane when I started writing it.
joshdavham•1h ago
I 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.

ismailmaj•24m ago
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 implement that. I did not. Blabbered something about Rust having sorted B-Trees and I don't think Python has them -- they do not on the standard library.

Then the interviewer leaned heavily on the "reduce memory usage" and I couldn't come up with a solution (no shit it's Ω(n) and he didn't even tell me to go fetch for a randomized algorithm). I later understood he expected the reservoir sampling solution which is basically keeping a representative group of size K that is a good proxy of the whole stream, it goes like this: keep the K first elements, any elements after that replaces any element of our sample at random.

What I did after 10 minutes of weird silence is to assume the data stream follows a normal distribution and computing the P-percentiles by computing the running mean and standard deviation.

I felt frustrated at the end of the interview because it really felt like a big gotcha of either you know the reservoir sampling "leetcode trivia" or you don't.

eventualcomp•17m ago
Yeesh. Data streaming algorithms. Can I import [1] datasketches-python in the interview?

[1] https://github.com/apache/datasketches-python

dekhn•14m ago
Literally the second I read "it's a data stream" I knew the answer was going to be reservoir sampling.

RS is really interesting to me. many people you talk to can realize you can compute the mean of a data stream (https://www.geeksforgeeks.org/web-tech/expression-for-mean-a...) without knowing the exact formulation. And it's not far from that to think of a sampling strategy to decide if a new sample should go into a fixed-size reservoir. (for all of these, I know specific hints that will usually help people get to the next step).

The only reason I know RS is because it was in the google3 monorepo and I was looking for interesting codes to use and found it. There was an associated Sharding class, LexicographicRangeSharding (https://www.mongodb.com/docs/manual/core/ranged-sharding/) which you could use to find near-optimal split points in sorted string tables so your mappers didn't end up with hotspots. If you had shown me Algorithm R in a stats class, I don't think I would have appreciated it at all, but seeing the code implementation and a useful example made it click.

ukoki•59m ago
Only the median (or pair around the median) needs to be sorted, the other numbers can be unsorted :)
AdieuToLogic•9m ago
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?
wewewedxfgdf•55m ago
Great question! Assuming the job requires calculating a lot of medians.
DonHopkins•6m ago
Don't be mean!
jagged-chisel•52m ago
> High-quality candidates …

Oh, you … ;-)

floxy•51m ago
https://en.wikipedia.org/wiki/Floyd%E2%80%93Rivest_algorithm
ta93754829•43m 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
Induane•27m ago
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.
meltyness•36m ago
without thinking about it or looking at the article, this feels rather radixy
hirvi74•35m ago
> # Python is pass-by-reference, what are the

> # implications of sorted() vs numbers.sort()?

I thought references were passed by value in languages like Python? I am not particularly fond of Python, so my experience with and knowledge of the language are quite limited. But, I understand what the question is asking: mutation vs. the creation of a new object.

minitech•33m ago
Correct, it’s a common misconception/sloppy wording.
AdieuToLogic•6m ago
A mental exercise I perform when "reference" is used in this context is to substitute it with "pointer." I find it clarifying and rarely, if ever, incorrect.
NooneAtAll3•29m ago
I thought this was going to be about computing (a+b)/2 avoiding overflows
foobar1962•25m ago
That's average or mean. Median is the middle value.

From the article:

> It can lead to some discussion about statistics and why you might prefer a median to a mean in most cases.

My best example for median vs mean is property prices, where very expensive properties will skew the mean (average value) upwards but the median (middle value) will remain about the same.

SeanSullivan86•12m ago
The overflow thing would be about computing the median of some sub-range of a sorted array. It is an often-quizzed thing that comes up as an edge case in binary search of a large array, but could apply to anything where you need to select the middle element of a sub-range of an array and the sum of the start/end indices could overflow.

I think the lore is that it was a bug in Java?'s binary search lib decades ago?

strstr•28m ago
Who does a sort for this D:
marseysneed•20m ago
You need the middle value. You cannot be certain what is the middle value without a sorted array, unless I am mistaken.
strstr•15m ago
You can definitely do this without sorting.

QuickSelect is average case n, and is, roughly, quick sort where you throw away one of the sides each time and recurse on the other. This has a fat tail for cases where you pick a bad pivot (similar to quicksort), but you can median-of-medians your way out of that problem if someone cares. (Median of medians being where you subdivide the array into, say, 5 arrays, recursively compute the median on those, and pick the middle median as your pivot, which guarantees linear progress per iteration)

scarmig•5m ago
You can solve it with two heaps, which don't need to maintain a complete order. Or selection algorithms, as in the sibling comment (asymptotically better).
dreamcompiler•24m ago
Even better question: Compute the moving median.

Computing a moving average with samples being pumped through an n-element buffer is easy. Doing so for the median requires more thought. It's also very useful e.g. for removing single-sample noise from an audio track, so it's not a meaningless exercise.

strstr•21m ago
I used to translate classic interview questions into not-spoiled-on-the-internet ones by doing this kind of batch to incremental conversion. The count-the-islands one was fun but hard to fit into a 45minute interview.

Eventually most of those started getting spoiled too lol.

tayo42•20m ago
Id screw this up assuming that sort and pick the middle is to obvious and do something dumb lol
SeanSullivan86•17m ago
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.

dimview•7m ago
You can do it a bit faster by not quicksorting the entire array, as you don't really care about the order of the lowest and highest numbers as long as they are not close to the middle.

There is also an approximate algorithm that does not keep all the data in memory at the same time.

keithnz•5m ago
I find this kind of thing too limited and you can't do much with it. I like to take problems from our domain. We work with all kinds of measurement data for agriculture / mining / utilities, I'll usually work through the problem of coming up with an alarm/alert system given a timeseries. It has relatively straight forward programming problems like simple on off threshold alerting and more complex issues like making predictors to decide when to irrigate for example. Depending on the level of the person we can do different things, talk about our domain and some of the problems in that domain. So we can go through specifying things, making design decisions, implementing an interesting aspect (usually not too complex with limited scope), next steps to build the system out, how to validate, logging, etc, feeling out how they'd approach making it production ready basically.

John Deere owners will get the right to repair equipment under FTC settlement

https://apnews.com/article/john-deere-right-to-repair-agriculture-equipment-cb7514ffedb95c130a976...
333•djoldman•2h ago•67 comments

I Think I Have LLM Burnout

https://www.alecscollon.com/blog/llm-burnout/
37•sosodev•25m ago•18 comments

A software engineering interview question I like: computing the median

https://krisshamloo.com/blog/007
45•speckx•1h ago•36 comments

Separating signal from noise in coding evaluations

https://openai.com/index/separating-signal-from-noise-coding-evaluations/
164•sk4rekr0w•5h ago•63 comments

Chatto is now open source

https://www.hmans.dev/blog/chatto-is-open-source
752•speckx•11h ago•201 comments

Remote Attestation

https://www.liamcvw.com/p/remote-attestation
26•lcvw•1h ago•12 comments

Patching MechCommander's "left arm bug" for fun and profit

https://mhloppy.com/2026/05/mechcommander-weapons-left-arm-bug-fix/
13•Narann•3d ago•2 comments

Mistral's Robostral Navigate: a state of the art robotics navigation model

https://mistral.ai/news/robostral-navigate/
418•ottomengis•12h ago•96 comments

Unicode's transliteration rules are Turing-complete

https://seriot.ch/computation/uts35/
40•beefburger•16h ago•10 comments

Show HN: Microsoft releases Flint, a visualization language for AI agents

https://microsoft.github.io/flint-chart/#/
209•chenglong-hn•8h ago•78 comments

Cloudflare Drop

https://www.cloudflare.com/drop/
265•coloneltcb•7h ago•135 comments

Grok 4.5

https://x.ai/news/grok-4-5
482•BoumTAC•8h ago•615 comments

MIRA: Multiplayer Interactive World Models Trained on Rocket League

https://mira-wm.com/
20•ethanlipson•1h ago•5 comments

Turning a pile of documents into a searchable useable knowledge base

https://github.com/linuxrebel/DocuBrowser
80•linuxrebe1•5h ago•15 comments

We made Grok 4.5, GPT-5.5, and Claude build the same apps

https://www.tryai.dev/blog/grok-4.5-vs-gpt-5.5-vs-claude-build-off
69•hershyb_•2h ago•29 comments

Show HN: Yamanote.fun – A complete soundscape for Tokyo's Yamanote line

https://www.yamanote.fun/
59•madebymagnolia•1d ago•15 comments

FAANG Simulator

https://www.abeyk.com/escape-the-rat-race/
291•nerdbiscuits•6h ago•114 comments

GPT‑Live

https://openai.com/index/introducing-gpt-live/
605•logickkk1•9h ago•415 comments

A bug which affected only left handed users

https://shkspr.mobi/blog/2026/07/a-bug-which-only-affected-left-handed-users/
90•sixhobbits•13h ago•44 comments

New Sweden: the US's long-lost 'secret' colony

https://www.bbc.com/travel/article/20260629-new-sweden-the-uss-long-lost-secret-colony
55•bookofjoe•6h ago•8 comments

My road trip with the do-gooding cactus smugglers

https://economist.com/1843/2026/03/06/my-road-trip-with-the-do-gooding-cactus-smugglers
20•andsoitis•3d ago•1 comments

TypeScript 7

https://devblogs.microsoft.com/typescript/announcing-typescript-7-0/
475•DanRosenwasser•10h ago•186 comments

Show HN: Frugon – Find which LLM calls a cheaper model could handle (local, MIT)

https://github.com/Rodiun/frugon
13•jarodrh•1d ago•2 comments

Decoding the obfuscated bash script on a Uniqlo t-shirt

https://tris.sherliker.net/blog/obfuscated-self-evaluating-bash-script-by-cdn-akamai-being-suppli...
1303•speerer•17h ago•209 comments

Rewriting Bun in Rust

https://bun.com/blog/bun-in-rust
303•afturner•4h ago•168 comments

OpenMandriva: Statement regarding attempted distribution sabotage

https://forum.openmandriva.org/t/statement-regarding-attempted-distribution-sabotage/8997
78•workethics•7h ago•13 comments

Beyond Git: Real-Time Version Control for Godot – Lilith Duncan – GodotCon 2026 [video]

https://www.youtube.com/watch?v=CAJ_iIedx_I
15•surprisetalk•6d ago•1 comments

Cloudflare Meerkat - Globally distributed consensus

https://blog.cloudflare.com/meerkat-introduction/
224•bobnamob•13h ago•45 comments

I Built a Telegram Client for Pi

https://www.npmjs.com/package/@atharva-again/pi-tg
57•atharva-again•2d ago•26 comments

EVE Online's Carbon engine is now open source: Fenris Creations explains why

https://www.gamesindustry.biz/eve-onlines-carbon-engine-is-now-open-source-fenris-creations-expla...
382•Stevvo•5d ago•135 comments