Find the second largest numeric digit that appears in a string.
Given a string s, scan all characters and consider only the digits '0' through '9'.
Return the second largest distinct digit that appears in s. If fewer than two distinct digits appear, return -1.
A digit is counted by its numeric value, and repeated digits only matter once for determining distinct values.
s: a string containing lowercase letters, digits, or other characters depending on the platform variant.Treat only characters '0' to '9' as digits.
Return the second largest distinct digit present in the string, or -1 if it does not exist.
-1.Example 1
Input
s = "dfa12321afd"
Output
2
Explanation
The distinct digits are 1, 2, and 3. The largest is 3 and the second largest is 2.
Example 2
Input
s = "abc1111"
Output
-1
Explanation
Only one distinct digit appears: 1.
Example 3
Input
s = "ck077"
Output
0
Explanation
The distinct digits are 0 and 7. The largest is 7 and the second largest is 0.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.