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.

&nbsp;
Example 1:

Input: s = "dfa12321afd"
Output: 2
Explanation: The digits that appear in s are [1, 2, 3]. The second largest digit is 2.


Example 2:

Input: s = "abc1111"
Output: -1
Explanation: The digits that appear in s are [1]. There is no second largest digit. 


&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 500
	s consists of only lowercase English letters and/or digits.


class Solution:
    def secondHighest(self, s: str) -> int:
        nums = []
        for char in s:
            if char.isdigit():
                nums.append(int(char))
        nums = [num for num in nums if num != max(nums)]
        if len(nums) >= 1: return max(nums)
        else: return -1
class Solution {
    public int secondHighest(String s) {
        int[] arr = new int[10];
        for(int i = 0;i<s.length();i++){
            if(s.charAt(i) - '0' <=9 & s.charAt(i)-'0' >=0){
                arr[s.charAt(i)-'0']++;
            }
        }
        boolean first = false;
        for(int i = 9;i>=0;i--){
            if(arr[i] !=0){
                if(first)
                    return i;
                else first = true;
            }
        }

        return -1;
    }
}
class Solution {
public:
    int secondHighest(string s) {
        // support variables
        int res[2] = {-1, -1};
        // parsing s
        for (char c: s) {
            // considering only numerical characters
            if (c >= '0' && c <= '9') {
                // normalising c
                c -= '0';
                // updating res
                if (c > res[0]) {
                    res[1] = res[0];
                    res[0] = c;
                } else if (c != res[0] && c > res[1]) res[1] = c;
            }
        }
        return res[1];
    }
};
/**
 * @param {string} s
 * @return {number}
 */
var secondHighest = function(s) {
    //let's start by getting rid of all the non-digits
    let myRegex = /\D/g
    s = s.replace(myRegex,'')
    var digits = s.split('')
    //at this point, digits is an array of all the digit characters that were originally in s
    digits.sort(function(a, b){return b - a}) //sort the array into descending order
    var res = new Set(digits) //turn the array into a set, to remove duplicates
    if(res.size <=1){
        //if the set is sized 1, then there is no second largest digit
        return -1
    }
    else{
        //otherwise, the second largest digit would be at index 1 (because we sorted the array into descending order)
        return [...res][1]
    }
};
Second Largest Digit in a String