Skip to content
HN On Hacker News ↗

Kris Shamloo

▲ 56 points 72 comments by speckx 6h ago HN discussion ↗

Pangram verdict · v3.3

We believe that this document is fully human-written

0 %

AI likelihood · overall

Human
100% human-written 0% AI-generated
SEGMENTS · HUMAN 1 of 1
SEGMENTS · AI 0 of 1
WORD COUNT 288
PEAK AI % 0% · §1
Analyzed
Jul 9
backend: pangram/v3.3
Segments scanned
1 windows
avg 288 words each
Distribution
100 / 0%
human / AI fraction
Verdict
Human
Pangram v3.3

Article text · 288 words · 1 segments analyzed

Human AI-generated
§1 Human · 0%

a software engineering interview question I like: computing the median 2026-05-03 I have a number of questions in my quiver when I'm giving technical interviews to candidates. They are all of a similar flavor. I don't ask puzzle questions, I find them low value. Instead, I ask questions that are straightforward but have a few angles with which to explore deeper topics.

Enter the humble median.

Write a function that takes an array of numbers and returns the median.

At a minimum: this will give you a "Fizz Buzz"-like signal that the candidate can actually program. Reducing an array of values is table stakes. Right out the gate: the numbers must be sorted. Should the function sort them? Should the caller? If the array was passed in by reference is it ok to mutate? How does the API design influence the performance? It has an off-by-one trap. Mind you I don't care if anyone falls into an off-by-one trap, I fall into them all the time, but you'll often get a chance to watch someone debug a small problem. It has a branch: an even length array versus an odd one. It can lead to some discussion about statistics and why you might prefer a median to a mean in most cases. Gives the candidate a chance for some extra points by being so readily testable. Gives the candidate a chance to display some standard library knowledge via statistics.

Here's a Python implementation with discussion comments.

def median(numbers: list[float]) -> float: if not numbers: raise ValueError("median called with empty list")

numbers = sorted(numbers) length = len(numbers) mid = length // 2

if length % 2 == 0: return (numbers[mid - 1] + numbers[mid]) / 2.0 else: return numbers[mid]