Amazon VO Coding Interview: Decrease All Monetary Values in a String by 15%

14 Views
No Comments

Write a function that takes in a string and decreases all monetary values in the string by 15%.

Examples:

// "I spent $100.00 on Amazon this week." -> "I spent $85.00 on Amazon this week."
// "This candy costs $1.00" -> "This candy costs $0.85"

This Amazon VO problem asks you to scan a string, find every monetary value, and reduce each one by 15%. A typical solution uses pattern matching to locate currency amounts, converts the numeric part, multiplies by 0.85, and then rebuilds the string while preserving all non-monetary text. The main challenges are detecting amount boundaries and formatting the updated value consistently.

END
 0