Roman to Integer
easy⏱ 15 mintypescriptchallengesproblem-solving-basic-
LEARN BY DOINGPut your intuition to work3 steps
Roman to Integer
Use the lesson’s examples and explanation to check your idea.
Personal reflection. Nothing is sent to an AI service.Sample case — your program reads stdin and prints to stdout.
Starter Convert a Roman numeral string to an integer.
I=1, V=5, X=10, L=50, C=100, D=500, M=1000
If smaller value before larger, subtract (IV=4). Otherwise add.
Example: 'MCMXCIV' → 1994 (M=1000 + CM=900 + XC=90 + IV=4)
Input format
A single line containing a Roman numeral string.
Output format
The integer value.
Constraints
1 ≤ s.length ≤ 15, valid Roman numeral in range [1, 3999]