Part 3: Data Structures Fundamentals
Why These Data Structures Matter
Arrays and Strings
My Relationship with Arrays
Core Array Patterns
Pattern 1: Two Pointers (Opposite Directions)
def reverse_string(s: list[str]) -> None:
"""
Reverse string in-place using two pointers
My approach: Swap characters from both ends
Time: O(n), Space: O(1)
"""
left, right = 0, len(s) - 1
while left < right:
# Swap characters
s[left], s[right] = s[right], s[left]
left += 1
right -= 1
# Test
chars = ['h', 'e', 'l', 'l', 'o']
reverse_string(chars)
print(chars) # ['o', 'l', 'l', 'e', 'h']Pattern 2: Two Pointers (Same Direction)
Pattern 3: Sliding Window (Fixed Size)
Pattern 4: Sliding Window (Variable Size)
String-Specific Problems
Hash Tables (Dictionaries)
When I Reach for Hash Tables
Core Hash Table Patterns
Pattern 1: Frequency Counter
Pattern 2: Complement Finding
Pattern 3: Detecting Duplicates
Linked Lists
My Linked List Journey
Linked List Node Definition
Core Linked List Patterns
Pattern 1: Two Pointers (Fast & Slow)
Pattern 2: Reverse Linked List
Pattern 3: Merge Operations
Stacks
When to Use Stacks
Core Stack Problems
Queues
Queue vs Stack
Implementation in Python
Queue Problem Example
Key Takeaways
Practice Problems
What's Next?
Last updated