Skip to content
Katabench
Try free

Integer to Roman

Medium About 15 min Free, no account needed

Write Roman numerals the way Romans did - greedily.

The brief

Convert an integer (1..3999) to its Roman numeral. The subtractive forms (IV IX XL XC CD CM) are mandatory: 4 is IV, never IIII.

The hidden trap

Emitting one symbol per decimal digit turns 4, 9, 40, 90, 400 and 900 into a pile of special cases that is easy to get subtly wrong. The hidden tests sit exactly on those boundaries (444, 900, 3999). There is a formulation in which the subtractive forms need no special handling at all.

Starter code

C#
using System;
using System.Text;

public class Solution
{
    // TODO: return the Roman numeral for the given integer (1..3999).
    public string IntToRoman(int num)
    {
        throw new NotImplementedException();
    }
}

How it is graded

Visible examples help you iterate. Hidden tests then cover edge cases and larger inputs, and every test reports server-measured time and allocated bytes.

C# coding challenges →

What it practices

Greedy algorithms
Make the locally best choice when an exchange argument proves it stays globally optimal.
String processing
Parse, scan and match text character by character with correct edge cases.

Related katas