Minimum Hidden Roman Value
Reported by candidates from Zopsmart's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this Zopsmart OA, reported December 2025, is treating it like a normal Roman numeral parser. It isn't. You pick whether to combine valid adjacent pairs, and you want the minimum total. Greedy parsing feels right and fails on edge cases. Filter the string down to I, V, X, L, C, D, M, then decide pair by pair. It's a small dynamic programming problem wearing a Roman costume. If you blank on the recurrence during the live assessment, StealthCoder is the invisible safety net that reads the problem and hands you the solution.
The problem
You are given a string text. Extract only the Roman numeral letters I, V, X, L, C, D, and M, preserving their original order. After extraction, parse the letters from left to right. You may either take one letter as its normal Roman value, or combine two adjacent extracted letters as one subtractive pair if the pair is one of IV, IX, XL, XC, CD, or CM. A combined pair contributes the second value minus the first value. Return the minimum total value obtainable by choosing which adjacent valid subtractive pairs to combine. Function minimumHiddenRomanValue(text: String) → int Examples Example 1 text = "I HAVE EATEN" return = 4 The extracted Roman letters are IV. Combining them as the subtractive pair IV gives value 4. Example 2 text = "XIV" return = 14 Take X as 10 and combine IV as 4, for a total of 14. Constraints text may contain arbitrary uppercase letters and spaces. Only I, V, X, L, C, D, and M are used after extraction.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Extract the Roman letters first, ignoring everything else. Then run a linear DP where dp[i] is the minimum value for the first i letters. Option one: dp[i] = dp[i-1] + value(s[i-1]). Option two: if s[i-2..i-1] is one of IV, IX, XL, XC, CD, CM, then dp[i] = dp[i-2] + value(second) - value(first). Take the smaller. That's O(n) time and O(1) space if you keep two rolling values. The pitfall is greedy: always combining a valid pair, or never combining, both break because a pair can overlap with a neighbor. Take XIV as an example. Overlap is fine because each letter is used once, but the choice interacts. Another trap is forgetting that the extracted letters are not required to form a valid real numeral. If you freeze on the transition during the live OA, StealthCoder can hand you the DP skeleton so you just verify it against the two examples.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Minimum Hidden Roman Value cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Zopsmart's OA.
Zopsmart reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Hidden Roman Value FAQ
What's the trick in Minimum Hidden Roman Value?+
Filter the text to Roman letters, then do a left-to-right DP. At each position, either add the single letter's value or, if the last two letters form an allowed subtractive pair, use second minus first. Keep whichever total is smaller.
Why doesn't greedy work here?+
Combining a pair changes what the next letter can pair with, since each letter is used once. Always combining or never combining ignores that interaction. DP checks both choices at every step, so you never lock in a bad early decision.
How hard is this one really?+
Easy to medium. The string filtering is trivial and the DP has just two transitions. Most of the difficulty is reading the statement carefully and realizing you're minimizing, not parsing a real numeral the standard way.
What edge cases should I test?+
Test an empty extraction (no Roman letters), a single letter, and strings with letters that form no valid pair. Also run the two given examples: I HAVE EATEN gives 4 and XIV gives 14. Spaces and non-Roman letters must be dropped before the DP starts.
How do I prepare for this in 48 hours?+
Write the rolling two-state DP from memory a couple of times, then hand-trace XIV. Also review the standard Roman to Integer problem for the value map. Reported at Zopsmart in December 2025, so expect similar small string DP twists.