Parse User-Entered Crypto Amounts Into Integer Base Units

Last updated: November 29, 2026

Quick Overview

Convert strings like '1,250.50 USDC' or '.25 SOL' into the asset's smallest integer unit using each asset's decimal precision, rejecting malformed, negative, zero or over-precise input.

Coinbase
Coding & Algorithms
Software Engineer
Coinbase
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Convert strings like '1,250.50 USDC' or '.25 SOL' into the asset's smallest integer unit using each asset's decimal precision, rejecting malformed, negative, zero or over-precise input.

Every send, buy and withdrawal at Coinbase starts with an amount typed by a user, and assets range from 6 decimals (USDC) to 18 (ETH). The interviewer checks that you avoid floats entirely, define a strict grammar and handle precision limits and separators correctly.

What the Interviewer Expects
  • Refuse to use float parsing because of binary rounding
  • Define the accepted grammar before coding
  • Scale using the asset's decimal places with string padding
  • Reject more fractional digits than the asset supports, after trimming trailing zeros
  • Write targeted tests for both valid and invalid input
Key Topics to Cover
string parsing
regular expressions
fixed-point arithmetic
input validation
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you support locales that use a comma as the decimal separator?
  • Should '1.000000000 BTC' (9 decimals of zeros) be accepted? Why?
  • How would you format base units back to a display string?
  • Where should this validation live: client, API or both?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: '<amount> <ASSET>'. Amount is digits with optional thousands separators in groups of three, an optional single dot and fractional digits, or a leading dot. No sign, no exponent. Output: `(ass...

High-Level Design

Split on whitespace into amount and ticker, look up decimals, validate comma placement on the whole part, then strip commas and match the amount against a strict regex. Trim trailing zeros from the fr...


Submit Your Answer
Markdown supported

Related Questions