Skip to content

Blog, page 3

Plain answers about algorithms, interviews and performance.

44 posts

Posts

Complexity

What is amortized time complexity

What is amortized time complexity? It is the cost per operation averaged over a worst-case sequence, which is why a dynamic array append is O(1) even though some appends copy the whole array. Here is the arithmetic, with real numbers.

10 min read
Complexity

Why does my solution get time limit exceeded?

Why does my solution get time limit exceeded when the logic is right? Because the growth rate does not fit the input limit. Here is how to estimate operations, spot hidden O(n) costs, and fix it with real numbers.

11 min read
Performance

Why is string concatenation in a loop slow

String concatenation in a loop is slow because immutable strings are copied in full on every append, which makes the total work quadratic. Here is the arithmetic, how Python, Java, JavaScript and Go differ, and the fix.

9 min read
Craft

Why is dynamic programming so hard?

Why is dynamic programming so hard? Because it is taught as a bag of solved problems when it is really a single skill: defining a state small enough to store and complete enough to recurse on. Get the state right and the recurrence, the base cases and the table order follow mechanically.

10 min read
Craft

Why is binary search so hard to get right?

Why is binary search so hard to get right? Because the idea is trivial and the boundaries are not: which interval you maintain, how you compute the midpoint, and when you stop each have one correct form and several plausible wrong ones. Here is the invariant that makes all three decisions for you.

9 min read
Data structures

When should you use a heap instead of sorting?

When should you use a heap instead of sorting? When you need only the k smallest or largest, when items arrive over time, or when you repeatedly need the current minimum. Sorting pays n log n once for everything; a heap pays log n per item for just what you ask. Here is where the crossover sits.

9 min read
Performance

Is recursion slower than iteration?

Is recursion slower than iteration? Usually by a small constant, sometimes not at all, and occasionally catastrophically, when the recursion recomputes subproblems or exhausts the stack. The real cost is not the function call; it is the shape of the work. Here is how to tell the three cases apart.

9 min read
Performance

Why is my hash map slow?

Why is my hash map slow? Almost always one of four things: a bad hash function, a load factor allowed to climb, keys that are expensive to hash or compare, or cache misses from a map far larger than L2. Here is how to tell which one you have, and what O(1) was actually promising.

9 min read
Interviews

How many LeetCode problems are enough?

How many LeetCode problems are enough before an interview? Around 100 to 150, chosen to cover the core patterns, beats 500 picked at random. The number that predicts your interview result is not problems solved; it is patterns you can recognise and re-derive cold. Here is how to count that instead.

9 min read
Interviews

Are brain teasers still asked in coding interviews?

Are brain teasers still asked in coding interviews? Big tech formally dropped them years ago, yet the reasoning they test never left: it just moved inside algorithm questions, estimation prompts, and quant screens. Here is where teasers survive in 2026 and how to prepare without memorising answers.

9 min read
Complexity

O(log n) vs O(n log n): what the difference actually means

The difference between O(log n) and O(n log n) is one question: does your algorithm have to touch every element? Binary search discards half the data and never reads most of it. Merge sort reads all of it, log n times over. Here is how to tell which one you wrote.

9 min read
Interviews

Coding interview patterns: the 15 that keep coming back

Most coding interview patterns lists are just problem tags. This is a working catalogue: 15 patterns, the cue that identifies each one, the invariant it protects, what it costs, and a walkthrough on this site to practise it on.

10 min read