Arrays and Strings
π Introduction
π― Python List Internals
Memory Layout
import sys
# Lists are over-allocated for efficiency
lst = []
print(f"Empty list: {sys.getsizeof(lst)} bytes")
for i in range(20):
lst.append(i)
print(f"Length {len(lst):2d}: {sys.getsizeof(lst)} bytes")
# Output shows capacity jumps:
# Length 1: 88 bytes
# Length 5: 120 bytes
# Length 9: 184 bytes
# ...Time Complexity of List Operations
Operation
Average
Worst
Notes
π Python String Internals
Immutability Implications
String Interning
π Two-Pointer Technique
Pattern 1: Opposite Direction
Pattern 2: Same Direction (Fast/Slow)
Pattern 3: Three Pointers
πͺ Sliding Window Technique
Fixed-Size Window
Variable-Size Window
π Prefix Sum Technique
π Common Array Problems
Kadane's Algorithm (Maximum Subarray)
Merge Intervals
Rotate Array
π€ Common String Problems
Anagram Check
Valid Parentheses (Stack-based)
Longest Common Prefix
π Practice Exercises
Exercise 1: Container With Most Water
Exercise 2: Minimum Window Substring
Exercise 3: Product of Array Except Self
π Key Takeaways
π What's Next?
π References
Last updated