Trains the technique from
LeetCode 1796Second Largest Digit in a StringThis 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 tag reads s, a mix of lowercase letters and digits.
Return the second largest digit appearing on the tag, counting each distinct digit once however often it appears. Return -1 when the tag has fewer than two distinct digits.
Example 1
The digits on the tag are 8, 4, 3 and 7. The largest is 8, so the runner-up is 7.
Example 2
Only two distinct digits appear, 5 and 2, however often each is repeated, so the runner-up is 2.
Example 3
The tag holds a single distinct digit, so there is no runner-up.
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 second_highest(s: str) -> int:public int secondHighest(String s)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.