FastPrepFastPrep
Problem Brief

Roman Numerals in Strings

OA

You are given a string that contains a name followed by Roman numerals.

Your task is to return a vector of strings that stores:

  • 1. The string name.
  • 2. The numerical value of the Roman numeral (converted to integer).

The names should be in ascending order, and if the names are the same, the numbers should also be sorted in ascending order.

Input Format:

- A list of strings where each string is in the format: name RomanNumeral.

Output:

Return a vector of strings, sorted by name and numeral value.

Notes:

- The Roman numeral, when converted to a number, is at most two digits.

1Example 1

Input
strings = ["John IX", "Mary XV", "John VIII", "Mary IX"]
Output
["John 8", "John 9", "Mary 9", "Mary 15"]
Explanation

The names and their corresponding Roman numerals are sorted in ascending order. The Roman numerals are converted to integers as follows:

  • IX -> 9
  • XV -> 15
  • VIII -> 8
  • IX -> 9

The sorted output is: ["John 8", "John 9", "Mary 9", "Mary 15"].

Constraints

Limits and guarantees your solution can rely on.

๐ŸŠ๐ŸŠ
public String[] romanNumeralsInStrings(String[] strings) {
  // write your code here
}
Input

strings

["John IX", "Mary XV", "John VIII", "Mary IX"]

Output

["John 8", "John 9", "Mary 9", "Mary 15"]

Sign in to submit your solution.