Strings & Two-Pointer MechanicsPhase 1

Stage 1 of 5
Foundational Mental Model

Strings & Two-Pointer Mechanics

Why this lesson right now?Adaptive Pedagogy

You encountered memory indexing and boundary traps in recent problem attempts. This 18-minute interactive module directly targets those exact gaps before advancing to downstream tree and graph traversals.

### What is a String? In most modern languages (Python, Java, JavaScript), a **String** is an array of characters with one critical characteristic: **immutability**.

Critical Nuance: Immutability - Modifying a single character in an immutable string (e.g. `s += "a"` in a loop) creates a **brand new string in memory**, turning what looks like $O(N)$ into an accidental $O(N^2)$ nightmare! - Solution: Use array lists or string builders (e.g., `[].join("")` in JS or `"".join(list)` in Python).

The Two-Pointer Technique One of the most famous patterns in competitive programming: 1. Initialize pointer `left` at index `0` and pointer `right` at index `N - 1`. 2. Move pointers inward while validating character equality (e.g. Palindrome verification) or reversing elements.

Time Complexity
Two-Pointer: O(N) | Concatenation: O(N)
Space Complexity
O(1) auxiliary with pointers