Roman Numerals in Strings
Updated
Problem statement
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.
Function
romanNumeralsInStrings(strings: String[]) → String[]Examples
Example 1
strings = ["John IX", "Mary XV", "John VIII", "Mary IX"]return = ["John 8", "John 9", "Mary 9", "Mary 15"]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
🍊🍊
More GreyOrange interview questions
Similar questions at other companies
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
- Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions
- Find a File in a Directory SnapshotCresta · OACresta interview questions
- Flat JSON Value DifferencesChubb · OAChubb interview questions
- Road Trip (Analyst Program :PBlackRock · OABlackRock interview questions
- Get Search ResultsJP Morgan Chase · OAJP Morgan Chase interview questions
- Lexicographic Word FrequenciesUpstart · OAUpstart interview questions
- Email Log Processing, Grouping, and SortingStripe · OAStripe interview questions
- Most Frequent CharacterMicrosoft · OAMicrosoft interview questions