Skip to content

Practice Second Largest Digit in a String

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#1796
LeetCode Problem

Second Largest Digit in a String

Problem Statement

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.

Source: Second Largest Digit in a String on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "dfa12321afd"
Output
2

# Example 2

Input
s = "abc1111"
Output
-1

Constraints

1 <= s.length <= 500
s consists of only lowercase English letters and digits.

Related LeetCode Problems

Practice more problems similar to Second Largest Digit in a String.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.