text made of lowercase English letters and digits. Among the distinct digits that appear in it, find the second largest one and return it as a number.
Repeats of the same digit do not count as different digits. If fewer than two distinct digits appear, return -1.text="room404floor7" → 4
The digits present are 0, 4 and 7. The largest is 7 and the next one down is 4.
text="agent007" → 0
There are two distinct digits, 0 and 7, so the second largest is 0.
text="x9y9z" → -1
Only one distinct digit, 9, appears, so there is no second.
text consists of lowercase English letters and digitstext="room404floor7"
4
Run checks the first 3 tests in your browser. Submit checks all 132 tests on the server, hidden ones included.