Roman to Integer
Easy · Math & Number Theory · about 10 minutes
Asked at Google, Meta, Microsoft, Amazon, Uber, Bloomberg.
Convert a Roman numeral (value 1–3999) to an integer. The symbols are worth I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000. Normally they are arranged from biggest to smallest and simply added up. The exceptions are six pairs where a smaller symbol in front is subtracted: IV = 4, IX = 9, XL = 40, XC = 90, CD = 400, CM = 900.