To follow up from my previous post, let's dig more into some patterns that revolve around heaps! When you're given a question that revolves around keeping track of k elements, a good bet is to think about solving the problem with heaps. Lets say you'...

If we have a problem where we're interested in knowing the smallest in element in one part of a given set of elements and the biggest element in the other part, we can use the two heaps pattern. Lets work through this problem together: Implement a cl...

Ah, a good old linked list problem. Some people love them, some people help them. Hopefully with this pattern, you'll love questions which ask you to reverse the links between a set of nodes of a linked list. It may sounds like a niche pattern but it...

This pattern is useful when dealing with problems involving arrays containing numbers in a range. How would you solve the following problem? Given n distinct numbers from 0 to n. Find the missing number. Key words to pick out here: distinct, 0 to n ...

This pattern is useful when dealing with interval questions. A lot of the questions will require us to merge overlapping intervals in a given list. First step to answering a question like this is to answer the following question: How many ways can tw...

This is quite a nifty pattern to apply to linked lists (also arrays and other sequences). Also known as: Hare and Tortoise algorithm. Floyd's algorithm. The pattern is famously used for cycle detection but can be used to solve other sorts of probl...