Integer to Roman - Problem
Convert an integer to its Roman numeral representation using the seven basic symbols:
Symbol Values:
I = 1V = 5X = 10L = 50C = 100D = 500M = 1000
Conversion Rules:
- Use largest possible values first (greedy approach)
- Special subtractive cases:
IV (4),IX (9),XL (40),XC (90),CD (400),CM (900) - Only append symbols consecutively up to 3 times (I, X, C, M)
- Never repeat V, L, D multiple times
Given an integer between 1 and 3999, return its Roman numeral string.
Input & Output
Example 1 — Standard Conversion
$
Input:
num = 3
›
Output:
III
💡 Note:
3 is represented as III (three ones: I + I + I = III)
Example 2 — Subtractive Case
$
Input:
num = 58
›
Output:
LVIII
💡 Note:
58 = 50 + 8 = L + VIII (50 as L, 8 as V + III)
Example 3 — Complex Number
$
Input:
num = 1994
›
Output:
MCMXCIV
💡 Note:
1994 = 1000 + 900 + 90 + 4 = M + CM + XC + IV
Constraints
- 1 ≤ num ≤ 3999
Visualization
Tap to expand
Understanding the Visualization
1
Input
Integer number (e.g., 1994)
2
Process
Use value-symbol pairs greedily from largest to smallest
3
Output
Roman numeral string (MCMXCIV)
Key Takeaway
🎯 Key Insight: Pre-include subtractive cases (IV, IX, XL, etc.) as single units to enable simple greedy selection
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code