Tap here to switch tabs
Problem
Ask
Submissions

Problem: Integer to Roman

med
30 min
Explore how to convert integers into their Roman numeral equivalents by applying greedy techniques. This lesson helps you understand the rules of subtractive notation and how to process each decimal place effectively, enabling you to implement an accurate and optimized solution.

Statement

Given an integer, num, convert it to its Roman numeral representation.

Roman numerals are built using the following 77 symbols:

Symbol

Value

I

1

V

5

X

10

L

50

C

100

D

500

M

1000

Roman numerals are constructed by converting each decimal place value from highest to lowest using these rules:

  • If the value does not start with 44 or 99, select the largest symbol whose value can be subtracted from the current value, append it to the result, subtract its value, and repeat for the remainder.

  • If the value starts with 44 or 99, use its subtractive form: one smaller symbol placed before a larger one. Only the following subtractive forms are valid: 44 (IV), 99 (IX), 4040 (XL), 9090 (XC), 400400 (CD), and 900900 (CM).

  • Only powers of 1010 ( I, X, C, M ) may be repeated consecutively, and at most 33 times. The symbols V, L, and D may never be repeated. If a symbol would need to appear 44 times, use the corresponding subtractive form instead.

Note: Conversion is applied digit by digit based on decimal place values. For example, 4949 is not treated as 11 less than 5050; instead, 4040 becomes XL and 99 becomes IX.

Constraints:

  • 11 \leq num 3999\leq 3999

Tap here to switch tabs
Problem
Ask
Submissions

Problem: Integer to Roman

med
30 min
Explore how to convert integers into their Roman numeral equivalents by applying greedy techniques. This lesson helps you understand the rules of subtractive notation and how to process each decimal place effectively, enabling you to implement an accurate and optimized solution.

Statement

Given an integer, num, convert it to its Roman numeral representation.

Roman numerals are built using the following 77 symbols:

Symbol

Value

I

1

V

5

X

10

L

50

C

100

D

500

M

1000

Roman numerals are constructed by converting each decimal place value from highest to lowest using these rules:

  • If the value does not start with 44 or 99, select the largest symbol whose value can be subtracted from the current value, append it to the result, subtract its value, and repeat for the remainder.

  • If the value starts with 44 or 99, use its subtractive form: one smaller symbol placed before a larger one. Only the following subtractive forms are valid: 44 (IV), 99 (IX), 4040 (XL), 9090 (XC), 400400 (CD), and 900900 (CM).

  • Only powers of 1010 ( I, X, C, M ) may be repeated consecutively, and at most 33 times. The symbols V, L, and D may never be repeated. If a symbol would need to appear 44 times, use the corresponding subtractive form instead.

Note: Conversion is applied digit by digit based on decimal place values. For example, 4949 is not treated as 11 less than 5050; instead, 4040 becomes XL and 99 becomes IX.

Constraints:

  • 11 \leq num 3999\leq 3999