I knew the symbols but blanked for a second on how to handle the subtractive cases cleanly.
Use a greedy algorithm with a value-symbol table that includes subtractive pairs (e.g., 900=CM, 400=CD, 90=XC, 40=XL, 9=IX, 4=IV). Iterate from largest to smallest, subtracting the value and appending the symbol while the remaining number is >= the value. This yields a clean O(1) solution since the input is bounded to 1–3999.
Pro tip: Mention that the greedy approach is provably optimal for Roman numerals because the value system is canonical and the subtractive pairs are explicitly included; also note that the input constraint (1–3999) means no special handling for zero or negative numbers is needed.
Confirm the input range (1–3999) and that standard Roman numerals are expected. Ask if zero or negative inputs need handling, though the problem states otherwise.
Create an ordered list of pairs from largest to smallest, including subtractive forms: 1000=M, 900=CM, 500=D, 400=CD, 100=C, 90=XC, 50=L, 40=XL, 10=X, 9=IX, 5=V, 4=IV, 1=I.
Iterate through the mapping; for each value, while the remaining number is >= value, append the symbol and subtract the value. This builds the numeral from left to right.
Return the constructed string. Optionally, verify by converting back or checking known examples (e.g., 1994 = MCMXCIV).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.