Second Largest Digit in a String - Problem
Given an alphanumeric string s, return the second largest numerical digit that appears in s, or -1 if it does not exist.
An alphanumeric string is a string consisting of lowercase English letters and digits.
Input & Output
Example 1 — Basic Mixed String
$
Input:
s = "dfa12321afd"
›
Output:
2
💡 Note:
Digits present: 1, 2, 3. Largest is 3, second largest is 2.
Example 2 — Duplicate Digits
$
Input:
s = "abc1111"
›
Output:
-1
💡 Note:
Only digit 1 appears, so there's no second largest digit.
Example 3 — No Digits
$
Input:
s = "abcdef"
›
Output:
-1
💡 Note:
No digits in the string, return -1.
Constraints
- 1 ≤ s.length ≤ 500
- s consists of lowercase English letters and digits.
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code