Problem 341035 · medium · Phase 03 Linear Management & Searching

Write a Roman Numeral

strings · greedy · lookup tables

The same museum catalogue (see the reading problem) must also print years. Given an integer n with 1 <= n <= 3999, return its Roman numeral using the standard subtractive forms IV, IX, XL, XC, CD, CM (never four identical symbols in a row).

Examples

Input:  n = 2026
Output: "MMXXVI"

Input:  n = 444
Output: "CDXLIV"

Constraints

  • 1 <= n <= 3999
  • Target: O(1) time (the table has 13 entries and the output has at most 15 symbols).

Goals

  • Order a value table from largest to smallest including the subtractive pairs
  • Subtract greedily while appending symbols
  • Build the result with a list and join
Starting Python…