Comparison [mp]
Micro pattern¶
Description¶
Use local comparisons to determine ordering, movement, search direction, or positional equality.
Problems¶
Compare active front elements¶
Select the smaller available front element when merging sorted sequences.
- Top-down merge sort (DSA)
- Top-down merge sort linked list (DSA)
- Bottom-up merge sort (DSA)
- Bottom-up merge sort linked list (DSA)
- 21. Merge Two Sorted Lists (Top Easy)
- 88. Merge Sorted Array (Top Easy)
- 148. Sort List (Top Hard)
Direct pointers or search boundaries¶
Compare an active value with a target or boundary to choose the next position.
- 15. 3Sum (Top Medium)
- 33. Search in Rotated Sorted Array (Top Medium)
- 162. Find Peak Element (Top Medium)
- 240. Search a 2D Matrix II (Top Medium)
- 11. Container With Most Water (Top Hard)
- 4. Median of Two Sorted Arrays (Top Hard)
- 42. Trapping Rain Water (Top Hard)
Custom ordering¶
Compare composed arrangements when ordinary ordering does not capture the objective.
- 179. Largest Number (Top Hard)
Positional equality¶
Compare structurally related positions while extending a run, path, or symmetric region.
- 5. Longest Palindromic Substring (Top Medium)
- 38. Count and Say (Top Medium)
- 79. Word Search (Top Medium)
- 13. Roman to Integer (Top Easy)
- 839. Similar String Groups (Graph Theory)
- 72. Edit Distance (Dynamic Programming)
- 712. Minimum ASCII Delete Sum for Two Strings (Dynamic Programming)
- 115. Distinct Subsequences (Dynamic Programming)
- 1143. Longest Common Subsequence (Dynamic Programming)
- 1035. Uncrossed Lines (Dynamic Programming)