easyStringHash TableArrays & Hashing

Roman to Integer

easyTime: O(n)Space: O(1)

Signals to notice

Roman numeral to integersymbol valuessubtraction rule

Brute force first

Map each symbol, add values left to right — misses subtraction cases. That instinct is useful because it follows the prompt literally, but it usually keeps revisiting work the problem is begging you to organize.

The key insight

If current symbol < next symbol, subtract instead of add. The goal is not to be clever for its own sake, but to remember the one relationship that keeps the solution grounded as you move forward.

What must stay true

When a smaller value appears before a larger one, subtract it (IV = 4, not 6). If that remains true after every update, the rest of the reasoning has a stable place to stand.

Easy way to go wrong

Not handling the subtraction rule — compare each symbol with the next one. When the code becomes mechanical before the idea is clear, small edge cases start breaking the whole story.

Arrays & Hashing Pattern