DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
String

String to Integer (atoi)

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **String to Integer (atoi)** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Handle whitespace, sign, overflow, invalid chars **Edge Cases to Consider:** - (1) Leading whitespace - (2) INT_MAX+1 overflow - (3) No digits after sign

Examples

Example 1
Input: "42"
Output: 42
Explanation: Simple
Example 2
Input: " -42"
Output: -42
Explanation: Leading spaces, negative
Example 3
Input: "4193 with words"
Output: 4193
Explanation: Stop at non-digit

Constraints

  • ▪1 <= s.length <= 10^4
  • ▪s consists of printable ASCII characters
  • ▪Solve with optimal space complexity

Watch Out For Edge Cases

  • ▪Leading whitespace
  • ▪INT_MAX+1 overflow
  • ▪No digits after sign
Frequently Asked At
AmazonMicrosoftGoogleAdobe