Warm-ups · 2 of 24
Second-largest distinct element
Return the second-largest distinct value in the array, or -1 if there isn't one (all values equal, or only one element).
Examples
Input nums = [12, 35, 1, 10, 34, 1]
Output 34
Input nums = [10, 10, 10]
Output -1
Every value is the same, so there's no second distinct value.
📘 New to this? Indexing and walking through an array explains the idea in a few minutes.