Convert an integer from 1 to 3999 to a Roman numeral. Roman numerals use combinations of seven symbols: I (1), V (5), X (10), L (50), C (100), D (500), and M (1000). Subtractive notation is used in specific cases: IV (4), IX (9), XL (40), XC (90), CD (400), and CM (900). Return null for invalid inputs (null or numbers outside the 1-3999 range).

Examples:

Input: num = 3 Output: "III" Explanation: 3 is represented as three I symbols Input: num = 58 Output: "LVIII" Explanation: L = 50, V = 5, III = 3 Input: num = 1994 Output: "MCMXCIV" Explanation: M = 1000, CM = 900, XC = 90, and IV = 4
Apex Code Editor

Welcome to Lightning Challenge!

Create an Account

Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.

Create account

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 #CodeEveryDay May 2026

Contest runs May 1 - 31. Complete challenges to climb the leaderboard!

Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In