Encode an Integer with Standard Roman Symbols

Quick Overview

Convert an integer from 1 through 3999 into standard Roman notation, respecting decimal places and the six subtractive forms.

Encode an Integer with Standard Roman Symbols

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Convert the integer `value` into its standard Roman-numeral representation. Write the decimal place contributions from largest to smallest, using this symbol table: | Symbol | Value | | --- | --- | | `I` | `1` | | `V` | `5` | | `X` | `10` | | `L` | `50` | | `C` | `100` | | `D` | `500` | | `M` | `1000` | Within a decimal place, ordinary values use the largest applicable symbol and then the remaining value. A place digit of four or nine uses its subtractive form. The only permitted subtractive pairs are `IV`, `IX`, `XL`, `XC`, `CD`, and `CM`, representing `4`, `9`, `40`, `90`, `400`, and `900` respectively. Consecutive repetition is limited to three copies of `I`, `X`, `C`, or `M`. The symbols `V`, `L`, and `D` cannot be repeated. Do not subtract across arbitrary decimal places: `49` is `XLIX`, not `IL`. Preserve the original `intToRoman` interface: one integer argument and a string result. ### Examples **Example 1** ```text Input: value = 2449 Output: "MMCDXLIX" ``` The contributions are `2000`, `400`, `40`, and `9`. **Example 2** ```text Input: value = 86 Output: "LXXXVI" ``` The tens contribute `LXXX` and the units contribute `VI`. ### Constraints - `1 <= value <= 3999`. - Return the Roman representation defined by the decimal-place and repetition rules above.

Overview: Convert an integer from 1 through 3999 into standard Roman notation, respecting decimal places and the six subtractive forms.

Amazon logo
Amazon
Oct 20, 2026
mediumSoftware EngineerOtherCoding & Algorithms
1
0

Problem

Convert the integer value into its standard Roman-numeral representation. Write the decimal place contributions from largest to smallest, using this symbol table:

SymbolValue
I1
V5
X10
L50
C100
D500
M1000

Within a decimal place, ordinary values use the largest applicable symbol and then the remaining value. A place digit of four or nine uses its subtractive form. The only permitted subtractive pairs are IV, IX, XL, XC, CD, and CM, representing 4, 9, 40, 90, 400, and 900 respectively.

Consecutive repetition is limited to three copies of I, X, C, or M. The symbols V, L, and D cannot be repeated. Do not subtract across arbitrary decimal places: 49 is XLIX, not IL.

Preserve the original intToRoman interface: one integer argument and a string result.

Examples

Example 1

Input: value = 2449
Output: "MMCDXLIX"

The contributions are 2000, 400, 40, and 9.

Example 2

Input: value = 86
Output: "LXXXVI"

The tens contribute LXXX and the units contribute VI.

Constraints

  • 1 <= value <= 3999 .
  • Return the Roman representation defined by the decimal-place and repetition rules above.