Trains the technique from
LeetCode 2288Apply Discount to PricesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A notice reads sentence, a run of words separated by single spaces with no space at either end.
A word is a price when it begins with '$' and every character after that is a digit, and there is at least one such digit. Any other word is left alone, including a bare "$" and anything with a non-digit after the '$'.
Every price is reduced by discount percent. Write the reduced amount with exactly two digits after a decimal point, keeping the leading '$'. Taking a whole number of percent off a whole amount always lands on an exact number of hundredths, so two digits is always enough and nothing has to be rounded.
Return the notice after every price has been marked down.
Example 1
The words "$1" and "$2" are prices and halve to "$0.50" and "$1.00". The word "5$" does not begin with the marker, so it is left alone.
Example 2
Taking 33 percent off 3 leaves 2.01, which written to two digits is "$2.01".
Example 3
The word is the marker with no digits after it, so it is not a price and is left unchanged.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def mark_down_prices(sentence: str, discount: int) -> str:public String markDownPrices(String sentence, int discount)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.