DEV Community

TildAlice
TildAlice

Posted on • Originally published at tildalice.io

15 Coding Interview Patterns: The Complete Reference

The Pattern Recognition Problem

Here's something that took me embarrassingly long to figure out: coding interviews aren't really about solving novel problems. They're pattern matching exercises dressed up as algorithmic puzzles.

I watched a candidate struggle with a sliding window problem for 40 minutes. They knew the algorithm existed—they'd solved similar problems before—but under pressure, they couldn't recognize when to apply it. The interviewer eventually gave a hint: "What if you didn't start fresh each time?" And suddenly it clicked.

That's the gap this post addresses. Not teaching you algorithms from scratch (there are textbooks for that), but building a mental index so you can look at a problem and think: "Ah, this is a monotonic stack situation."

Pattern 1: Two Pointers

The most underrated pattern. When you have a sorted array or linked list and need to find pairs that satisfy some condition, two pointers often gets you from $O(n^2)$ brute force to $O(n)$.


python
def two_sum_sorted(nums: list[int], target: int) -> list[int]:
    """Find indices of two numbers that add to target. Array must be sorted."""
    left, right = 0, len(nums) - 1

    while left < right:
        current_sum = nums[left] + nums[right]
        if current_sum == target:
            return [left, right]
        elif current_sum < target:
            left += 1  # need bigger sum
        else:
            right -= 1  # need smaller sum

    return []  # no solution found


---

*Continue reading the full article on [TildAlice](https://tildalice.io/coding-interview-15-patterns/)*
Enter fullscreen mode Exit fullscreen mode

Top comments (0)