Trains the technique from
LeetCode 13Roman to IntegerThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Harborside dockhands write whole quantities using a shorthand built from seven marks:
S stands for 1H stands for 5K stands for 10P stands for 50T stands for 100W stands for 500Z stands for 1000A tally is normally written heaviest mark first, and its quantity is then just the total of its marks, so PKKSS reads 50 + 10 + 10 + 1 + 1 = 72. To keep a tally short a dockhand may put one lighter mark directly in front of a heavier one, and that lighter mark is then taken off the heavier one instead of added to it. Exactly six such pairings are ever written: SH for 4, SK for 9, KP for 40, KT for 90, TW for 400 and TZ for 900.
Given a tally code that a dockhand wrote correctly, return the quantity it stands for.
Example 1
Two K marks contribute 10 each, then S sits in front of the heavier H, so that pairing contributes 4.
Example 2
The heavy marks add up to 1000 + 500 + 100 + 10, and the trailing pairing adds 4.
Example 3
No mark is lighter than the mark to its right, so every mark is simply added.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def tally_value(code: str) -> int:public int tallyValue(String code)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.