Skip to content
Decoder

Integer to Roman

Medium

Problem

Convert an integer num to a Roman numeral. Use the symbols I (1), V (5), X (10), L (50), C (100), D (500), M (1000), and the six subtractive forms IV (4), IX (9), XL (40), XC (90), CD (400), CM (900). A symbol never repeats more than three times in a row.

Example 1

Input
num = 3
Output
"III"

Example 2

Input
num = 58
Output
"LVIII"

Example 3

Input
num = 1994
Output
"MCMXCIV"

Constraints

  • 1 <= num <= 3999

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.