13. Roman to Integer

Practice Roman to Integer for free on NudgeCode: Easy, Array & Hash Table pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Roman numerals use I=1, V=5, X=10, L=50, C=100, D=500 and M=1000, normally written largest first and added up. Six pairs subtract instead: IV=4, IX=9, XL=40, XC=90, CD=400, CM=900. Convert the numeral s to an integer.

Example

s = "LVIII"    ->  58
s = "MCMXCIV"  ->  1994

Constraints