Two Pointers
Abstract Idea:
- Use two pointers (or indices) to traverse data from one or both ends, often to find a condition involving pairs or subsequences.
Pattern:
- Youâre comparing elements from two places (beginning & end, or two sequences).
- Youâre told to find pairs or triplets.
- Problem involves sorted data or linked list.
Problems:
String: Unequal length handling
Abstract Idea:
- One part of the input runs out before the other â the solution must gracefully handle incomplete data or imbalanced structure.
Pattern:
- Youâre merging, comparing or aligning multiple structures of different sizes.
- One side might finish early or the strings âmay not be the same lengthâ.
Problems: