Back to problems
Sign in to unlock
Leetcode
Medium
Strings
Math
Greedy
Integer to Roman
Convert an integer into its Roman numeral representation.
Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Roman to Integer
gfgProblem Statement
Problem
Given a positive integer, convert it to a Roman numeral string.
Roman numerals use the following symbols:
| Symbol | Value |
|---|---|
| I | 1 |
| V | 5 |
| X | 10 |
| L | 50 |
| C | 100 |
| D | 500 |
| M | 1000 |
Roman numerals are formed by combining symbols from largest value to smallest value. Some values use subtractive notation:
- 4 =
IV - 9 =
IX - 40 =
XL - 90 =
XC - 400 =
CD - 900 =
CM
Write a program that returns the Roman numeral for the given integer.
Notes
- Use the standard Roman numeral rules for values in the usual interview range.
- The output should be the shortest valid Roman numeral representation.
Input Format
- A single integer
num. numis a positive whole number.
Output Format
- Return a string representing
numin Roman numerals.
Constraints
num > 0- Standard Roman numeral conversion is expected.
- In common interview settings,
numis typically within the range representable with the standard symbols.
Examples
Sample cases returned by the problem API.
Example 1
Input
58
Output
LVIII
Explanation
50 + 5 + 1 + 1 + 1 = 58, so the numeral is L + V + III = LVIII.
Example 2
Input
1994
Output
MCMXCIV
Explanation
1994 = 1000 + 900 + 90 + 4, which maps to M + CM + XC + IV.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.