/12. Integer to Roman

12. Integer to Roman

Medium
Hash Table70.6% acceptance

Given an integer value in the range [1, 3999], convert it to its Roman numeral representation as a string. Roman numerals are formed by combining the following symbols and values: I=1, V=5, X=10, L=50, C=100, D=500, M=1000. Subtractive notation is used for 4 (IV), 9 (IX), 40 (XL), 90 (XC), 400 (CD), and 900 (CM). Only powers of 10 (I, X, C, M) can be repeated up to three times in succession. Return the Roman numeral string corresponding to the input integer.

Example 1

Input: integer_value=2421

Output: MMCDXXI

Explanation: 2000 = MM, 400 = CD, 20 = XX, 1 = I

Example 2

Input: integer_value=83

Output: LXXXIII

Explanation: 50 = L, 30 = XXX, 3 = III

Example 3

Input: integer_value=1459

Output: MCDLIX

Explanation: 1000 = M, 400 = CD, 50 = L, 9 = IX

Constraints

  • 1 <= integer_value <= 3999
  • Input is a positive integer
Python (current runtime)

Case 1

Input: integer_value=2768

Expected: 'MMDCCLXVIII'

Case 2

Input: integer_value=3999

Expected: 'MMMCMXCIX'

Case 3

Input: integer_value=120

Expected: 'CXX'

Case 4

Input: integer_value=7

Expected: 'VII'

Case 5

Input: integer_value=1111

Expected: 'MCXI'