DSA Master › Topic 19
Additional Challenging Patterns
These problems mix patterns you already know. Merge sort can count inversions. BFS works on implicit graphs like Word Ladder. Swim in Rising Water combines Dijkstra with binary search. Job Scheduling combines DP with binary search.
Concepts
- Merge-sort counting
- BFS on grids/words
- Dijkstra / binary search on grids
- DP on squares & palindromes
- DP + binary search
How to recognise it
- You need to count pairs (i < j) that meet a condition. Count during merge sort.
- The problem asks for the fewest transformations or steps. Use BFS on an implicit graph.
- Weighted intervals (Job Scheduling): sort them, then DP with binary search.
Common pitfalls
- Expand around the centre for palindromes, checking both odd and even lengths.
- Word Ladder: try each character position with each letter a–z, not every pair of words.
Problems
- Count of Smaller Numbers After Self (Hard)
- Reverse Pairs (Hard)
- Shortest Path in Binary Matrix (Medium)
- Word Ladder (Hard)
- Swim in Rising Water (Hard)
- Maximal Square (Medium)
- Palindromic Substrings (Medium)
- Longest Palindromic Substring (Medium)
- Maximum Profit in Job Scheduling (Hard)
- Maximum Number of Events That Can Be Attended (Medium)