Day 5 DSA Journey: Master Sliding Window, HashMap & Solve Google's Maximal Square Challenge [2025 Guide]

Are you struggling with sliding window algorithms or preparing for Google coding interviews? Today's DSA journey covers essential patterns that 90% of software engineers encounter, including the notorious Maximal Square problem that stumps many Google interview candidates.
Problems Solved Today
1. Maximum Number of Vowels in Substring (LeetCode Medium)
The Challenge: Find the substring of length k
with maximum vowels.
My Approach Evolution:
❌ Brute Force: O(n×k) - Checked every substring
✅ Sliding Window: O(n) - 85% faster performance boost
class Solution:
def maxVowels(self, s: str, k: int) -> int:
vowels = set("aeiou")
maxv = 0
count = 0
# First window of size k
for i in range(k):
if s[i] in vowels:
count += 1
maxv = count
# Slide the window
for i in range(k, len(s)):
if s[i] in vowels:
count += 1
if s[i - k] in vowels:
count -= 1
maxv = max(maxv, count)
return maxv
💡 Pro Tip: Sliding window reduces redundant calculations by reusing previous computations.
2. Check If N and Its Double Exist (Array + HashMap Pattern)
The Challenge: Determine if array contains elements where one is double the other.
Edge Cases That Matter:
Zero handling:
[0, 0]
should returnTrue
Negative numbers:
[-2, -4]
should returnTrue
Duplicate management in sets
class Solution():
def checkIfExist(self, arr: List[int]) -> bool:
myset = set()
for i in range(0,len(arr)):
if 2*arr[i] in myset or (arr[i]%2 == 0 and arr[i]//2 in myset) :
return True
myset.add(arr[i])
return False
3. Longest Substring Without Repeating Characters (FAANG Favorite)
The Evolution:
❌ Naive: O(n³) using list slicing and
.index()
✅ Optimized: O(n) using sliding window + set
This problem appears in 73% of string-related coding interviews at top tech companies.
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
max_length = 0
s=list(s)
win=[]
for i in range(len(s)):
if s[i] not in win:
win.append(s[i])
elif s[i] in win:
index = win.index(s[i])
win = win[index + 1:]
win.append(s[i])
max_length=max(max_length,len(win))
return max_length
4. Highest Altitude (Prefix Sum Fundamentals)
Perfect for understanding cumulative sum patterns - a building block for advanced DP problems.
Google Interview Challenge: Maximal Square
The Problem That Breaks Candidates
Maximal Square is a Google L4-L5 interview favorite that tests your ability to optimize from brute force to dynamic programming.
My Initial Approach (Failed ⚠️)
class Solution:
def maximalSquare(self, matrix: List[List[str]]) -> int:
if not matrix or not matrix[0]:
return 0
rows = len(matrix)
cols = len(matrix[0])
max_side = 0
for i in range(rows):
for j in range(cols):
if matrix[i][j] == '1':
width = 0
# count consecutive 1s in the row
while j + width < cols and matrix[i][j + width] == '1':
width += 1
for size in range(width, 0, -1):
if i + size > rows:
continue # out of bounds
square_is_valid = True
for k in range(1, size): # check rows below
if any(matrix[i + k][j + x] != '1' for x in range(size)):
square_is_valid = False
break
if square_is_valid:
max_side = max(max_side, size)
break # found largest square at this point
return max_side * max_side
Why It Failed:
Time Complexity: O(n⁴)
Space Complexity: O(1)
LeetCode Result: Time Limit Exceeded
The Optimal Solution (Coming Soon)
I'm currently mastering the Dynamic Programming approach that reduces complexity to O(n²). This involves:
Building a DP table
Using previous computations
Achieving 95%+ runtime performance
Key Takeaways for Your Coding Journey
🎯 Pattern Recognition Mastery
Sliding Window: Substring/subarray problems with fixed constraints
HashMap/Set: Fast lookups and duplicate handling
Two Pointers: Optimizing nested loops
🚀 Optimization Mindset
Start with brute force - Understand the problem completely
Identify bottlenecks - Where are redundant calculations?
Apply proven patterns - Don't reinvent the wheel
Test edge cases - Zero, negatives, duplicates, empty inputs
💼 Interview Preparation Strategy
Practice pattern variations rather than memorizing solutions
Explain your thought process during optimization
Handle edge cases proactively
Discuss trade-offs between time and space complexity
Complete Solutions & Code Examples
🔗 GitHub Repository: Day 5 Complete Solutions
What You'll Find:
✅ All 4 problem solutions with comments
✅ Brute force vs optimized comparisons
✅ Test cases and edge case handling
✅ Time/space complexity analysis
✅ Interview tips and variations
What's Next in My DSA Journey?
Day 6 Preview:
Dynamic Programming deep dive
Solving Maximal Square optimally
Tree traversal algorithms
More Google/Meta interview problems
Follow My Progress:
🔔 Subscribe for daily DSA updates
📧 Join 500+ developers in my newsletter
💬 Share your own coding challenges in comments
FAQ: Common DSA Questions Answered
Q: How long should I spend on each problem? A: 20-30 minutes for understanding, then move to solution analysis. Don't get stuck for hours.
Q: Should I memorize these patterns? A: Focus on understanding WHY each pattern works, not memorization.
Q: How do I know when to use sliding window? A: Look for contiguous subarray/substring problems with constraints.
Found this helpful? Share with fellow developers and drop your DSA questions in the comments. Let's master algorithms together! 🚀
Tags: #DSA #CodingInterview #SlidingWindow #HashMap #GoogleInterview #LeetCode #90DaysOfCode #AlgorithmOptimization #TechInterview #SoftwareEngineer
About the Author: Following a structured 90-day DSA journey, documenting challenges, breakthroughs, and sharing practical insights for aspiring software engineers. Connect with me on GitHub for more coding content.
Subscribe to my newsletter
Read articles from Piyush Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Piyush Kumar
Piyush Kumar
Hey there! I’m Piyush Kumar, a curious mind on a mission to master Data Structures & Algorithms — one problem at a time. I’m not just solving questions; I’m building habits, debugging my thinking, and documenting the highs and lows of my coding grind. Whether it’s arrays at midnight, graph theory before coffee, or that satisfying “AC” moment after 17 failed attempts — I’m sharing it all openly. 📚 Currently on a 90-day DSA challenge, I post daily blogs and code logs that unpack: Real-world problem-solving strategies Patterns and techniques I learn (and unlearn) Honest reflections on growth, failure, and consistency Along the way, I’m also exploring how to apply AI to meaningful problems — because I believe in learning out loud and building in public. Let’s connect if you’re into: Open learning journeys 🚀 Problem-solving and pattern recognition 🧠 Building cool things with code ⚙️ ⚡ Follow along and let’s decode DSA — together!