FastPrepParse a Valid Roman Numeral

Parse a Valid Roman Numeral

Motive logoMotive● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Given a string roman, return its integer value if it is the canonical uppercase Roman-numeral representation of a value from 1 through 3999. Return -1 otherwise.

Function

parseValidRoman(roman: String) → int

Examples

Example 1

roman = "MCMXCIV"return = 1994

Example 2

roman = "IIII"return = -1

Constraints

  • 1 <= roman.length <= 20.
  • roman contains uppercase English letters.

More Motive problems

See Motive hiring insights
public int parseValidRoman(String roman) {
  // write your code here
}
roman"MCMXCIV"
expected1994
Checking account…