System Design Nuggets

System Design Nuggets

Coding Patterns & Algorithms

5 Algorithms You Need to Know to Pass Your Coding Interview

Learn the foundational algorithms every software engineer needs. We break down Binary Search, Sliding Window, Dynamic Programming, and more in this guide.

Arslan Ahmad's avatar
Arslan Ahmad
Jan 17, 2026
∙ Paid

The technical interview process is stressful.

You have spent months learning syntax and building projects, but then you sit down for an interview and they ask you to invert a binary tree or find a missing number in a massive dataset. It feels like a completely different skill set.

Many junior developers hit a wall here.

You might know how to build a React app or set up a database, but algorithmic problem-solving requires a specific way of thinking. It is not just about getting the code to work. It is about getting the code to work efficiently.

The good part is that you do not need to memorize a thousand different solutions. Most interview questions are actually variations of a few core patterns.

If you understand the underlying algorithm, you can apply it to dozens of different problems.

In this post, we are going to break down five of the most common algorithms you will encounter. We will skip the complex mathematical notation and focus on the logic.

1. Binary Search

If you are dealing with a sorted dataset, Binary Search is your best friend. It is the gold standard for efficiency when you need to find a specific item.

The Problem with Linear Search

Imagine you have an array of 1,000,000 sorted integers. You want to find the number 900,000.

A “brute force” approach would start at the very first index and check every single number one by one.

In the worst-case scenario, if your number is at the very end, you have to perform 1,000,000 operations. In computer science terms, we call this O(n) time complexity. It works, but it is slow.

How Binary Search Works

Binary Search takes a smarter approach. Because the data is sorted, we can make assumptions.

  1. Find the Middle: You look at the element exactly in the middle of the array.

  2. Compare: Is the middle number the one you are looking for?

    • If yes, you are done.

    • If the middle number is higher than your target, you know your target must be in the left half. You can instantly ignore the entire right half of the array.

    • If the middle number is lower than your target, you know your target is in the right half. You ignore the entire left half.

  3. Repeat: You take the remaining half and find the middle again.

Why It Matters

By cutting the search space in half every time, you drastically reduce the work. For 1,000,000 items, a linear search might take 1,000,000 steps. Binary search takes only about 20 steps.

The key takeaway here is logarithmic time complexity, or O(log n). whenever you see a problem involving a “sorted array,” your brain should immediately think of Binary Search.

2. Two Pointers

The Two Pointers technique is exactly what it sounds like. Instead of using a single reference point (like a loop variable i) to iterate through your data, you use two.

The Concept

Data structures like arrays or strings are linear. Usually, we iterate through them from start to finish. But sometimes, we need to compare elements at different positions simultaneously.

The Two Pointers pattern usually involves creating two variables:

  • Left Pointer: Starts at the beginning (index 0).

  • Right Pointer: Starts at the end (index length - 1).

How It Works

Let’s say you need to reverse an array of numbers in place (without creating a new array).

  1. You initialize your left pointer at the start and your right pointer at the end.

  2. You swap the values at the left and right indices.

  3. You move the left pointer one step forward.

  4. You move the right pointer one step backward.

  5. You repeat this until the pointers meet in the middle.

Another Variation: Slow and Fast Pointers

Sometimes, both pointers start at the beginning. One pointer moves one step at a time (slow), and the other moves two steps at a time (fast).

This is incredibly useful for detecting cycles in a Linked List. If a list loops back on itself, the fast pointer will eventually “lap” the slow pointer and catch up to it from behind.

If there is no loop, the fast pointer will simply reach the end.

This algorithm transforms what could be a complex nested loop solution (taking O(n^2) time) into a linear solution (O(n) time).

User's avatar

Continue reading this post for free, courtesy of Arslan Ahmad.

Or purchase a paid subscription.
© 2026 Arslan Ahmad · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture