Trains the technique from
LeetCode 3121Count the Number of Special Characters IIThis 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 document has up to 26 sections, each tagged by one letter of the alphabet. An audit trail arrives as the string log, one character per touch, read left to right in the order the touches happened:
A section is settled when the trail shows at least one draft touch on it, at least one approval touch on it, and no draft touch on it after its earliest approval touch.
Return how many sections are settled.
Example 1
Section p is drafted at positions 0 and 1 and approved at position 2. Section q is drafted at position 3 and approved at position 5, and section r is drafted at position 4 and approved at position 6. All three have every draft touch ahead of their first approval.
Example 2
Section m is drafted at position 0, approved at position 1, then drafted again at position 2. That final draft touch comes after the approval, so the section is not settled.
Example 3
Section g is drafted at position 3 and approved at position 4, so it is settled. Section f is drafted at positions 0, 1 and 5 and approved at position 2, and the touch at position 5 falls after that approval.
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_promoted_letters(log: str) -> int:public int countPromotedLetters(String log)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.