// https://leetcode.com/problems/second-largest-digit-in-a-string/description/
public static int secondHighest(String s) {
Set<Integer> set = new TreeSet<>((x, y) -> y - x);
for (char c : s.toCharArray()) {
if (Character.isDigit(c)) {
set.add(Character.digit(c, 10));
}
}
if (set.size() <= 1) {
return -1;
}
var iterator = set.iterator();
iterator.next(); // first
return iterator.next(); // second
}