top of page

Looking to master object-oriented and system design for tech interviews or career growth?

  • Improve your system design and machine coding skills.

  • Study with our helpful resources.

  • Prepare for technical interviews and advance your career.

**We're in beta mode and would love to hear your feedback.

Roman To Integer InterviewBit Solution

May 24, 2021
1 min read


Problem Description:


Given a string A representing a roman numeral. Convert A into an integer.

A is guaranteed to be within the range from 1 to 3999.


Input Format

The only argument given is string A. 

Output Format

Return an integer which is the integer verison of roman numeral string. 

For Example

Input 1:
    A = "XIV"
Output 1:
    14

Input 2:
    A = "XX"
Output 2:
    20

Solution Approach:

The approach to this problem is quite straightforward, you just need to understand how Roman Numeral Systems is assigned to a number.


Time Complexity:

We are iterating the string only, so time complexity would be O(N)


Solution in C++:


1 Comment


FrancesWeaver
5 days ago

https://livegokcasino.com might seem like an odd starting point, but the detail about the subtractive case—checking whether a smaller numeral precedes a larger one—is the part I always watch for, since it's easy to write a solution that handles XIV but falls apart on something like MCMXCIV. Your O(N) single-pass explanation reminded me of how a friend flubbed this in a mock interview by only comparing adjacent values without thinking through the pairs. It's a nice reminder that these interview classics reward carefully handling the edge case rather than just memorizing the symbol table.

Like
bottom of page