SSkills PlaygroundALGORITHMS / 04
INTERACTIVE LESSON

A foundation for interview problems

String
Manipulation.

Strings are sequences of character codes. Learn how to inspect them, transform them, and avoid hidden work when assembling new text.

String manipulation

Timed TypeScript practice

String manipulation

Write your solution, use the timer, then validate TypeScript types and syntax. Your code is never executed.

30:00
Strict TypeScript validation · no execution

Performance, step by step

String manipulation

Character range checks

O(1)

One or two comparisons against character-code boundaries decide whether a character is a letter or digit.

Split

O(n)

Scan each character once, placing completed pieces into the result whenever the delimiter appears.

Join

O(total output)

Every character from every piece, plus every separator, must appear in the returned string.

Naive string matching

O(n × m)

Try the pattern at each position of the text and compare up to m characters per attempt.

Building an immutable string with +

can be O(n²)

Each append may copy the string built so far. Collect pieces in an array, then join once instead.

LESSON04Text, decoded

CHARACTER INSPECTOR

Letters and digits live in consecutive code ranges. Comparing a character against the range is often all you need.

CHARACTERmCODE POINT109
A — Z
65 — 90
a — z
97 — 122
0 — 9
48 — 57

m is a lowercase letter.

The detail that changes the algorithm

In many languages,
strings do not mutate.

Appending with result += char can create a fresh string and copy everything already built. In a loop, that repeated copying can become the bottleneck.

Instead, collect characters or pieces in a dynamic array. When the work is complete, join them once. You still create the final string, but you avoid rebuilding its growing prefix over and over.

Three common operations

Trace the text.

Every character has a job.
01 / SPLIT

Break on

splitbyspace

Scan left to right. At each delimiter, save the current piece and start a new one.

02 / JOIN

Rebuild with

split by space

The output must contain every piece and separator, so the work is proportional to its length.

03 / MATCH

Find by

index 6split by space

A basic matcher tests the pattern at each possible starting position.

CHARACTER CODES

Use the sequential ranges for English letters and digits when a problem calls for low-level character checks.

BUILT-INS

Know your language’s split, join, and search APIs—but be ready to explain the underlying scan.

IMMUTABILITY

When building text incrementally, favor an array or builder and create the finished string once.