Skip to main content
Back to problems
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

gfg
Problem Statement

Problem

Given a positive integer, convert it to a Roman numeral string.

Roman numerals use the following symbols:

SymbolValue
I1
V5
X10
L50
C100
D500
M1000

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.
  • num is a positive whole number.

Output Format

  • Return a string representing num in Roman numerals.

Constraints

  • num > 0
  • Standard Roman numeral conversion is expected.
  • In common interview settings, num is 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
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.