Strings · Coding problem
Roman to Integer
A free coding problem from the String Symbol Mapping skill. Read it here, then solve it in the app in Java or Python.
- Easy
- Coding problem
- Free
- Java and Python
The problem
Given a Roman numeral s, convert it to an integer.
Example
Input: s = "MMXXVI"
Output: 2026
Roman numerals use subtractive notation: a smaller symbol written just before a larger one is subtracted from it (IV = 4, CM = 900).
Constraints
1 <= s.length <= 15scontains only the charactersI V X L C D Msis a valid Roman numeral in the range[1, 3999]
How it's graded
- Run checks your code against the examples. Submit also runs a hidden suite in four groups - basic cases, edge cases, random inputs and performance tests at the size limit - and shows which groups pass, never the hidden inputs.
- Stuck? Hints come in four steps, from a nudge to a code skeleton, each costing part of the points.
- Once you pass, you see the approaches from brute force to optimal, and where your solution lands among them.
More problems in String Symbol Mapping
Solve it Roman to Integer free
No card needed. Lessons, practice questions and easy problems are free forever.
Free plan, no card · 7-day Pro trial · Cancel anytime