FastPrepRoman to Integer

Roman to Integer

Kotak Mahindra Bank logoKotak Mahindra Bank● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Given the canonical uppercase Roman-numeral representation of an integer from 1 through 3999, return its integer value.

The subtractive pairs are IV, IX, XL, XC, CD, and CM.

Function

romanToInteger(roman: String) → int

Examples

Example 1

roman = "III"return = 3

The signed local contribution of each symbol reproduces canonical additive and subtractive notation.

Example 2

roman = "IV"return = 4

The signed local contribution of each symbol reproduces canonical additive and subtractive notation.

Example 3

roman = "IX"return = 9

The signed local contribution of each symbol reproduces canonical additive and subtractive notation.

Constraints

  • 1 <= roman.length <= 15.
  • roman is the canonical uppercase representation of a value from 1 through 3999.

More Kotak Mahindra Bank problems

See Kotak Mahindra Bank hiring insights
public int romanToInteger(String roman) {
    // Write your code here.
}
roman"III"
expected3
Checking account…