Zepruv › Coding problems

Second Largest Digit in a String

Easy · Hash Table, 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

Input: s = "dfa12321afd"
Output: 2

The digits that appear in s are [1, 2, 3]. The second largest digit is 2.

Example 2

Input: s = "abc1111"
Output: -1

The digits that appear in s are [1]. There is no second largest digit.

Constraints

Starter code (python)

class Solution(object):
    def secondHighest(self, s):
        """
        :type s: str
        :rtype: int
        """
        

Related problems

Previous: Car Fleet II · Next: Check if Binary String Has at Most One Segment of Ones · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.