Roman to Integer
Easy About 10 min Free, no account needed
Read Roman numerals, subtractive pairs included.
The brief
Convert a valid Roman numeral (I V X L C D M) to an integer. Six subtractive
pairs exist: IV IX XL XC CD CM.
Summing symbol values one at a time reads IX as 11. A symbol smaller than
its right neighbor subtracts instead of adds, the visible tests include easy
numerals, the hidden ones stack several subtractive pairs.
Starter code
using System;
public class Solution
{
// TODO: return the value of a Roman numeral.
public int RomanToInt(string s)
{
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.
What it practices
- String processing
- Parse, scan and match text character by character with correct edge cases.
Related katas
- Add Binary Strings Easy Free Add two binary numbers far too long for any built-in integer.
- Maximum Bracket Depth Easy Free How deep do the parentheses nest? A counter beats a stack.
- Base64 Decoded Length Easy Free The decoded size is pure arithmetic - no need to decode.
- Count Distinct Letters Easy Free How many different letters appear? A 26-slot array already knows.