mediumStringArrays & Hashing

String to Integer (atoi)

mediumTime: O(n)Space: O(1)

Signals to notice

parse string to integerhandle whitespace signs overflowedge case intensive

Brute force first

Not applicable — parsing IS the task.

The key insight

Sequential: skip whitespace → read sign → read digits → clamp to INT range. O(n).

What must stay true

Process one concern at a time. Check overflow BEFORE multiplying: if result > INT_MAX/10, clamp.

Easy way to go wrong

Overflow during digit accumulation — check before result = result * 10 + digit, not after.

Arrays & Hashing Pattern