‹ DS&A interview · Socratic
DSA · Math · #87

Integer to Roman

Module 58 · difficulty 3/5·30:00starts on first keystroke

Roman numerals are written by combining seven symbols: `I=1`, `V=5`, `X=10`, `L=50`, `C=100`, `D=500`, `M=1000`. Numbers are formed by placing symbols from largest to smallest and adding their values, except for six subtractive cases: `IV=4`, `IX=9`, `XL=40`, `XC=90`, `CD=400`, `CM=900`. Implement `intToRoman(num)` that converts an integer `num` (1 to 3999) into its Roman numeral string.

Examples
  • num = 3749 "MMMDCCXLIX"3000 = MMM, 700 = DCC, 40 = XL, 9 = IX.
  • num = 58 "LVIII"50 = L, 8 = VIII.
  • num = 1994 "MCMXCIV"1000 = M, 900 = CM, 90 = XC, 4 = IV.
Constraints
  • · 1 <= num <= 3999
Session phases
A · Clarify
B · Approach
C · Complexity
D · Edges
E · Code
F · Tradeoff
G · Score
Phase A — Clarify
Ask questions about input bounds, types, and edge constraints.
Ask the coach clarifying questions about the problem.
When you've covered this phase, advance to the next.