Trains the technique from
LeetCode 58Length of Last WordThis 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 dock scanner prints one line of routing text per pallet. The text is made only of English letters and blank spaces, and a run of letters with no blank inside it forms a single tag. Blanks are used purely as separators: the printer pads unpredictably, so a line can start with blanks, end with blanks, and carry several blanks between two neighbouring tags.
The rightmost tag on the line is the one the loader keys in, and the operator wants to know how many characters that tag occupies.
Report how many letters make up the final tag of line. Every line holds at least one tag, and padding blanks are never part of a tag.
Example 1
The final tag is `ready`, which occupies five characters.
Example 2
Padding sits at both ends of the print, and the rightmost tag is still `bay` with three letters.
Example 3
Three blanks separate the two tags, and the one on the right, `pier`, has four letters.
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 trailing_tag_length(line: str) -> int:public int trailingTagLength(String line)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.