String to Integer (atoi)
mediumTime: O(n)Space: O(1)
Recognize the pattern
parse string to integerhandle whitespace signs overflowedge case intensive
Brute force idea
Not applicable — parsing IS the task.
Better approach
Sequential: skip whitespace → read sign → read digits → clamp to INT range. O(n).
Key invariant
Process one concern at a time. Check overflow BEFORE multiplying: if result > INT_MAX/10, clamp.
Watch out for
Overflow during digit accumulation — check before result = result * 10 + digit, not after.