FastPrepMinimum Hidden Roman Value
Problems/Minimum Hidden Roman Value

Minimum Hidden Roman Value

ZopSmart logoZopSmartOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given a string text. Keep only the Roman numeral letters I, V, X, L, C, D, and M, in the order they appear. Drop every other character.

Then read the kept letters from left to right. At each step, either take one letter at its usual Roman value, or take the next two kept letters together as one pair. A pair is allowed only if it is IV, IX, XL, XC, CD, or CM. A pair is worth the second letter's value minus the first letter's value.

You choose which allowed pairs to join. Return the smallest total you can get.

Function

minimumHiddenRomanValue(text: String) → int

Examples

Example 1

text = "I HAVE EATEN"return = 4

The kept Roman letters are IV. Taking them one at a time would give six. Joining them as the pair IV gives 4, which is smaller.

Example 2

text = "XIV"return = 14

Take X as 10 and join IV as 4, for a total of 14.

Constraints

  • text may contain any uppercase letters and spaces.
  • Only I, V, X, L, C, D, and M are kept.

More ZopSmart Online Assessment questions

  • Base36 Square RootOA · Seen Dec 2025
  • Reverse Base36 NumberOA · Seen Dec 2025
See ZopSmart hiring insights
Saved
class Solution {
    public int minimumHiddenRomanValue(String text) {
      // write your code here
    }
}
Checking account…