Practice Apply Discount to Prices
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
A sentence is a string of single-space separated words where each word can contain digits, lowercase letters, and the dollar sign '$'. A word represents a price if it is a sequence of digits preceded by a dollar sign. You are given a string sentence representing a sentence and an integer discount. For each word representing a price, apply a discount of discount% on the price and update the word in the sentence. All updated prices should be represented with exactly two decimal places. Return a string representing the modified sentence. Note that all prices will contain at most 10 digits.
Source: Apply Discount to Prices on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
sentence = "there are $1 $2 and 5$ candies in the shop", discount = 50
"there are $0.50 $1.00 and 5$ candies in the shop"
# Example 2
sentence = "1 2 $3 4 $5 $6 7 8$ $9 $10$", discount = 100
"1 2 $0.00 4 $0.00 $0.00 7 8$ $0.00 $10$"
Constraints
Related LeetCode Problems
Practice more problems similar to Apply Discount to Prices.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.