#️⃣ PHP Hashing — Topic Index
Hashing maps keys to values using a hash function, enabling O(1) average-time lookups, inserts, and deletes. PHP arrays act as hash maps natively.
Topics Covered
| # | Topic | Key Concepts |
|---|---|---|
| 1 | Basics | Hash maps, sets, frequency counting, PHP arrays |
| 2 | Patterns | Two-sum, grouping, prefix sums, sliding window |
| 3 | Interview Questions | 25 classic problems |
Why Hashing?
- O(1) average lookup/insert/delete — transforms O(n²) brute force into O(n)
- Frequency counting — character/word counts in O(n)
- Prefix sums — subarray problems solved with running sum maps
- Deduplication — instantly check if element was seen before
Common Patterns
- Two-pointer complement lookup —
target - xin map - Frequency map — count occurrences, find majority element
- Prefix sum + map — subarray sum equals k
- Sliding window + freq — minimum window substring, anagrams
- Index tracking — longest substring without repeat, first unique char