A Must-Know Basic Concept for Coding Interviews
Photo by Ellen Tanner on Unsplash

Non-Members here :)

Grinding/ Grinded LeetCode?

If yes, you’ve probably come across the sliding window technique.

Why Bother with Sliding Windows?

Imagine you’re calculating maximum sums for subarrays. The rookie move? Checking every. Single. Combination. That’s O(n²) time — a death sentence for large datasets.

But what if you could recycle your calculations instead of starting from scratch each time?

That’s the sliding window’s dirty secret. You keep 90% of your previous work, tweak the edges, and boom — you’re down to O(n) time.

The Nutshell Guide (Fixed-Size Edition):

1️⃣ Build Your First Window: Calculate the result for the first K elements.
2️⃣ Slide Like You Mean It:

  • Kick out the leftmost element
  • Welcome the new right element
  • Update your result faster than a TikTok trend

3️⃣ Rinse and repeat until you’ve covered the entire array.

Now picture this:

You’re in a coding interview, sweating bullets as the interviewer throws a “find all anagrams” problem at you. Your mind races — do you brute-force it and risk a timeout, or is there a smarter way?

Enter the sliding window technique.

I’ve grilled (and been grilled by) dozens of engineers, and let me tell you — this method is gold for problems involving subarrays or substrings. No magic, just clever optimization.

Real Talk from Interview Experience
After sitting on both sides of the table (50+ interviews and counting), here’s how I sniff out whether candidates truly get sliding windows (especially Round 1):

“Find the max sum of size K subarrays” (the warm-up)

“Find all anagrams in a string” (where 30% of candidates faceplant)

Kadane’s algorithm for maximum subarray (yes, it’s DP — so the window mindset can make things hard!)

The Cost of Skipping This

I’ve seen brilliant coders bomb interviews because they overlooked sliding windows.

Don’t be that person.

Master this, and you’ll:

  • Turn “impossible” optimizations into “oh, that was easy” moments
  • Have a killer answer for 30% of substring/subarray questions
  • Look like you’ve got a PhD in problem-solving (even if you’re just starting out)

PS: If your solution for “Minimum Window Substring” still gives you nightmares, you’re not alone. We’ve all been there. 🥲