I knew the symbols but blanked on how to cleanly handle the subtractive pairs.
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 greater than or equal to the value.
Pro tip: Mention that the greedy approach works because the Roman numeral system is canonical for 1–3999, and note that the input range guarantee simplifies handling of large numbers and invalid inputs.
Confirm the input range (1–3999) and discuss behavior for invalid inputs (e.g., 0 or >3999). Mention that the range ensures no symbols beyond M are needed.
Create a list of pairs in descending order, including standard symbols (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1) with their Roman representations.
Iterate through the mapping, and while the number is >= the current value, append the symbol and subtract the value. This naturally handles subtractive notation.
State that time complexity is O(1) because the number of symbols is bounded (max 15 iterations). Test with edge cases like 4, 9, 40, 90, 400, 900, and 3999.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.