Back to Home
String Manipulation
Strings are fundamental in coding interviews. Since they are essentially arrays of characters, many array techniques apply.
Key Concepts
-
Character Encoding: Characters map to numeric codes (ASCII and Unicode).
- Sequential Ranges: Lowercase ('a'-'z'), uppercase ('A'-'Z'), and digits ('0'-'9') have sequential codes. This allows checking ranges (e.g.,
'a' <= c <= 'z') without memorizing ASCII values. - Conversion: Know your language's functions to convert between char and int (e.g., Python's
ord()/chr(), Go's byte conversion).
- Sequential Ranges: Lowercase ('a'-'z'), uppercase ('A'-'Z'), and digits ('0'-'9') have sequential codes. This allows checking ranges (e.g.,
-
Mutability & Performance:
- In languages like Python, Java, and JavaScript, strings are immutable. Modifying them creates a new string.
- Performance Trap: Concatenating strings in a loop (
s += c) is often because it copies the entire string each time. - Solution: Use a Dynamic Array (Python list, JS array) or StringBuilder (Java, Go's
strings.Builder) to build strings in , then join/convert at the end.
Practice Problems
Is Alphanumeric
Easy
Practice this problem with interactive visualization.
Start Solving
To Uppercase
Easy
Practice this problem with interactive visualization.
Start Solving
String Split
Medium
Practice this problem with interactive visualization.
Start Solving
String Join
Medium
Practice this problem with interactive visualization.
Start Solving
String Matching
LeetCodeMedium
Practice this problem with interactive visualization.
Start Solving