The Three Questions That Tanked My Onsite

Three problems from a senior backend onsite I failed in 2024. A median-of-stream I overcomplicated, a string compression where I missed a case, and a queue-with-min I never finished. Plus what I should have written.

Question Bundle
Python
3 questions
interview-prep
onsite-interview
algorithms
sanjayward

By @sanjayward

April 17, 2026

·

Updated August 11, 2026

783 views

21

4.4 (13)

Round 1: design a data structure that supports add(x) and median() on a stream of integers. I jumped to a balanced BST and ran out of time. The interviewer wanted two heaps.

What I actually wrote at the board

I started sketching an AVL tree with order statistics. Forty minutes in I had insertion working and no median; the interviewer politely moved on.

class MedianFinder:
    def __init__(self):
        self.data = []

    def add(self, x):
        self.data.append(x)
        self.data.sort()

    def median(self):
        n = len(self.data)
        if n == 0:
            return None
        if n % 2:
            return self.data[n // 2]
        return (self.data[n // 2 - 1] + self.data[n // 2]) / 2