Second Largest Digit in a String

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.

Example 1
Inputs = "dfa12321afd"
Output2
The digits that appear in s are [1, 2, 3], and the second largest digit is 2.
Example 2
Inputs = "abc1111"
Output-1
The digits that appear in s are [1], so there is no second largest digit.

Constraints

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

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate