Convert Roman Number to Decimal (Integer) | Write Python Program to Convert Roman to IntegerIn this tutorial, we will write the Python program to convert the Roman numbers into the integer. It is a popular problem was asked by the tech giant Amazon, Facebook in the interview. Let's see the problem statement and implementation of the solution. Problem StatementA roman number is given as a string; the task is to convert the corresponding integer value. The symbols are given below for reference.
Example 1: Input:s = VI Output: 6 Example 2: Input: XOutput: 10XL is a Roman symbol which represents 40 Solution ApproachAlgorithm
Let's implement the algorithm to the Python program. ProgramOutput: 7 Explanation In the above code, we define a rom_value() function which returns corresponding to the symbol. Next we define the romanTointeger() method which converts the value roman value to integer. In the romanToInteger() method,
Complexity AnalysisTime Complexity: O(n), where n is the length of the string. Only one traversal of the string is required. Space Complexity: O(1). As no extra space is required |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India