Parse Localized Money Strings Into Minor Units
Last updated: November 29, 2026
Quick Overview
Write a parser that turns strings like 'USD 1,234.50', 'EUR -1.234,56' or 'JPY 1500' into a (currency, integer minor units) pair, using each currency's grouping and decimal separators, and rejecting malformed inputs.
PayPal
November 29, 20260
0
0 solved
Write a parser that turns strings like 'USD 1,234.50', 'EUR -1.234,56' or 'JPY 1500' into a (currency, integer minor units) pair, using each currency's grouping and decimal separators, and rejecting malformed inputs.
PayPal operates in more than 200 markets, and amount parsing bugs (a misplaced separator turning 1.234 euros into 1,234) are real incidents. This easy online assessment question checks careful string handling, strict validation, and the habit of converting to integer minor units immediately.
What the Interviewer Expects
- Look up separators and decimal digits per currency
- Validate grouping positions rather than just stripping separators
- Convert to integer minor units without floats
- Reject unsupported currencies and too many decimal digits
- Handle a leading minus sign
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you add currencies with three decimal digits like KWD or BHD?
- How would you accept symbols such as '$' or trailing currency codes?
- Where should this parsing happen in a payments API: client, edge or core service?
- How would you fuzz test this parser?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input format is <CODE> <amount>. USD groups with , and uses . for decimals (2 digits). EUR groups with . and uses , (2 digits). JPY has no decimals. Grouping is optional, but if present must...
High-Level Design
Drive everything from a per-currency config so adding a market is a data change. Build one strict regular expression per currency: an integer part that is either plain digits or properly grouped digit...