FastPrepRoman Numeral to Integer
Problems/Roman Numeral to Integer

Roman Numeral to Integer

Scale AI logoScale AI● EasyINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2024 Scale AI SWE intern report says the first problem in the live coding round was about Roman numerals. The interviewer moved on to a different problem because the candidate had not worked with Roman numerals before.

The report does not say what the Roman numeral task asked. Here, you turn a standard Roman numeral into a number. Turning a number into a Roman numeral is the other common version and is not used. The subtraction pairs and the range 1 to 3999 are our choices.

Our version is about 50% the same as the reported question.

Roman numerals use seven letters. Each letter stands for a value:

LetterValue
I1
V5
X10
L50
C100
D500
M1000

Letters are usually written from the largest value to the smallest, and their values are added. For example, CLXI is 100 + 50 + 10 + 1 = 161.

Six pairs use subtraction instead. In each pair, a smaller letter comes right before a larger one, and the pair is worth the larger value minus the smaller one:

  • IV is 4 and IX is 9.
  • XL is 40 and XC is 90.
  • CD is 400 and CM is 900.

You are given a string roman. It is the standard Roman numeral for a whole number from 1 to 3999. Standard means the thousands, hundreds, tens and ones are written in that order, and each digit uses its usual form. For example, 4 is IV (never IIII) and 90 is XC (never LXXXX).

Return the number that roman stands for.

Function

romanToInteger(roman: String) → int

Examples

Example 1

roman = "XXVII"return = 27

No letter is followed by a larger one, so just add: 10 + 10 + 5 + 1 + 1 = 27.

Example 2

roman = "XLIX"return = 49

XL is a subtraction pair worth 40, and IX is worth 9. So the value is 40 + 9 = 49.

Example 3

roman = "MMCDXXI"return = 2421

MM is 2000, CD is 400, XX is 20 and I is 1. The total is 2421.

Constraints

  • 1 <= roman.length <= 15
  • roman is the standard Roman numeral for a whole number from 1 to 3999.

More Scale AI Phone Screen questions

  • Four-Player Trick-Taking Card Game SimulationOA · PHONE SCREEN · Seen Aug 2026
  • Task Processor: Dependencies and DeadlinesPHONE SCREEN · Seen Aug 2026
  • Best Poker Category with a JokerPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
  • Free Time for Every Meeting RoomPHONE SCREEN · Seen Apr 2026
  • Free Windows Between Busy IntervalsOA · PHONE SCREEN · Seen Apr 2026
  • Order Queries by Shortest Processing TimePHONE SCREEN · Seen Apr 2026
  • Party Time by Town and Quiet Gaps by CityPHONE SCREEN · Seen Jan 2026
  • Party Windows and Dead Zone TimePHONE SCREEN · Seen Oct 2025
  • Overlap Duration of Two Time IntervalsPHONE SCREEN · Seen Jun 2025
  • Multi-Head Attention BlockPHONE SCREEN · Seen Mar 2025

Similar questions at other companies

  • Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions
  • Reorderable Task Scheduler With CooldownWaymo · PHONE SCREENWaymo interview questions
  • Parse, Normalize, and Combine PolynomialsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
  • Text Embedding and Vector SearchNike, Inc. · PHONE SCREEN · ONSITE INTERVIEWNike, Inc. interview questions
  • Per-Segment SpeedingOnePay · PHONE SCREENOnePay interview questions
  • Rank Bipedal Dinosaurs by SpeedMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Count Sentences From Anagram SwapsAdobe · PHONE SCREENAdobe interview questions
  • In-Memory URL ShortenerRevolut · PHONE SCREENRevolut interview questions
  • Simplify a Formula with Known and Unknown VariablesBetter.com · PHONE SCREEN
  • Reconstruct Digits from Jumbled English WordsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions

Interview reports that mention this question

  • Scale AI SWE Intern Debugging Interview: 9 Experiences

Scale AI interview experiences

  • Scale AI Forward Deployed Engineer Debugging Round: 1 Experience
  • Scale AI ML Research Engineering Intern Interviews: 1 Experience
  • Scale AI New Grad SWE and MLE Question Bank
  • Scale AI New Grad SWE Poker Screen and Onsite: 1 Experience
  • Scale AI New Grad SWE OA Questions: 1 Experience
All Scale AI interview questionsSee Scale AI hiring insights
Saved
class Solution {
    public int romanToInteger(String roman) {
        // Write your code here.
    }
}
Checking account…