Integer to Roman

Medium · Math & Number Theory · about 15 minutes

Asked at Microsoft, Google, Amazon, Meta, Bloomberg, JPMorgan Chase, Two Sigma.

Convert an integer num (1 ≤ num ≤ 3999) to a Roman numeral. Use the symbols I V X L C D M (1, 5, 10, 50, 100, 500, 1000) and the subtractive forms IV, IX, XL, XC, CD, CM (4, 9, 40, 90, 400, 900).