Trains the technique from
LeetCode 1358Number of Substrings Containing All Three CharactersThis 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 parcel hub sends every parcel down one of three chutes, which the crew label r, g and b. The shift log is a string log where the character at each position names the chute used by that parcel, in the order the parcels went through.
A stretch is any run of one or more consecutive positions of log. A stretch is covering when at least one parcel inside it went down each of the three chutes.
Count the covering stretches. Two stretches are different when they begin at different positions or end at different positions, even when they read the same. Return that count.
Example 1
Numbering the positions from 1, the covering stretches are 1-3, 1-4, 1-5, 2-4, 2-5 and 3-5. Each of those six holds a parcel for chute r, one for chute g and one for chute b.
Example 2
Chute b never appears in the log, so no stretch can hold a parcel for all three chutes.
Example 3
Chute g is used only by the last parcel, so a covering stretch has to end at position 6. The four that also reach back to an r and a b are 1-6, 2-6, 3-6 and 4-6.
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 count_full_stretches(log: str) -> int:public int countFullStretches(String log)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.