6  Strings

Published

December 31, 2025

Strings

Unraveling the patterns within text. From anagrams to complex pattern matching.

7 Strings: More Than Just Text

I used to think strings were boring. Just text, right? Wrong. Strings are where I learned that “hidden complexity” is a real thing.

My realization: Strings are just arrays of characters, but with a lot more edge cases (case sensitivity, whitespace, encodings).

7.1 Core Concepts

7.1.1 1. String Basics

  • String representation in memory
  • String immutability
  • Common operations (concatenation, slicing, searching)

7.1.2 2. Common Operations

7.1.3 3. Advanced Topics

  • Regular expressions
  • String compression
  • String interleaving
  • String partitioning

7.2 Common Patterns

  1. Two-pointer technique
  2. Sliding window
  3. Hashing for frequency counting
  4. String matching algorithms (KMP, Rabin-Karp)
  5. Suffix trees and arrays

7.3 Time Complexity Cheat Sheet

Operation Time Complexity
Access O(1)
Search O(n)
Insert O(n)
Remove O(n)
Concatenation O(n + m)
Substring O(k) where k is substring length

7.4 Practice Problems

  1. Valid Palindrome
  2. Longest Substring Without Repeating Characters
  3. Group Anagrams
  4. Longest Palindromic Substring
  5. String to Integer (atoi)

7.5 Tips for Interviews

  1. Always clarify character set (ASCII, Unicode)
  2. Consider case sensitivity
  3. Handle edge cases (empty string, single character, very long strings)
  4. Consider using string builder for concatenation in loops
  5. Be familiar with built-in string methods in your language of choice