Trains the technique from
LeetCode 557Reverse Words in a String IIIThis 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 sign shop is setting a banner from the text line. The text holds one or more words written left to right, each pair of neighbouring words separated by exactly one space, with no space before the first word or after the last. A word is a run of characters that contains no space, and its characters may be letters, digits or punctuation.
The shop wants a mirrored banner: every word keeps its place in the line, but the characters inside each word are set in the opposite order.
Return the text of the mirrored banner, with the words still separated by a single space.
Example 1
Each of the four words is set backwards, and the four words stay in the order they were given, still one space apart.
Example 2
Digits and punctuation are characters of their word like any other, so they move with the rest of the word.
Example 3
Two of these words read the same backwards, so only the first word changes.
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 flip_each_word(line: str) -> str:public String flipEachWord(String line)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.