Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Arrays & strings

Ready to read

JSJavaScript⑂Git◎Interview prepΣDSA in JSSDSystem Design
More topics15›
</>HTML{ }CSS⚛ReactNNext.jsNeNest.jsTSTypeScriptNoNode.js🐳DockerDBSQL & Databases✓Testing🔒Web Security☁Cloud & DevOps◈GraphQL◆Redis☸Kubernetes
☰‹›
Description
All topics›JavaScript›Arrays & strings

Roman to Integer

beginnerlayer B2 · Arrays & strings4 tests

Write romanToInt(s) converting a valid Roman numeral into a number.

  • The symbols are I=1, V=5, X=10, L=50, C=100, D=500, M=1000
  • Symbols normally sit in descending order and are added together
  • When a smaller symbol sits directly before a larger one it is subtracted instead, so IV is 4 and CM is 900
  • You may assume the input is a well-formed numeral from 1 to 3999

Stuck?

All exercisesPlayground
1234567891011121314
loading the editor…

Nothing yet — hit Run and whatever you log shows up here.

Submit to see how you did.

⌘/Ctrl + Enter run⌘/Ctrl + S save⌘/Ctrl + / comment⌘/Ctrl + F find/replace⌘/Ctrl + D select next matchAlt + click multi-cursorTab indent · ⇧Tab outdentEsc leave fullscreen