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

Roman to Integer

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Roman to Integer** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Hash map; subtract if current < next **Edge Cases to Consider:** - (1) Single numeral - (2) Subtractive cases (IV, IX, etc.) - (3) Maximum Roman (MMMCMXCIX=3999)

Examples

Example 1
Input: "III"
Output: 3
Example 2
Input: "LVIII"
Output: 58
Explanation: 50+5+3
Example 3
Input: "MCMXCIV"
Output: 1994
Explanation: Classic

Constraints

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

Watch Out For Edge Cases

  • ▪Single numeral
  • ▪Subtractive cases (IV, IX, etc.)
  • ▪Maximum Roman (MMMCMXCIX=3999)
Frequently Asked At
AmazonMicrosoftGoogleAdobeTCS