FunctionRacerProblemsRace

Integer to Roman

EasyGreedyPython, JavaScript, TypeScript, Java, C++

Write num in Roman numerals. The symbols are I=1, V=5, X=10, L=50, C=100, D=500, M=1000. Numerals are written largest first, but 4, 9, 40, 90, 400 and 900 use subtraction: IV, IX, XL, XC, CD, CM. Return the numeral as a string.

Example 1

num 58
returns "LVIII"

L (50) + V (5) + III (3).

Example 2

num 1994
returns "MCMXCIV"

M + CM + XC + IV.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Greedy problems