Roman to Integer
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M, corresponding to values 1, 5, 10, 50, 100, 500, and 1000. For example, 2 is written as II, 12 is written as XII, and 27 is written as XXVII. However, 4 is written not as IIII but as IV — the I is placed before the V. The same principle applies to 9 (IX), 40 (XL), 90 (XC), 400 (CD), and 900 (CM). Given a roman numeral, convert it to an integer.
Examples
Constraints
- 1 <= s.length <= 15
- s contains only the characters ('I', 'V', 'X', 'L', 'C', 'D', 'M').
- It is guaranteed that s is a valid roman numeral in the range [1, 3999].
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.