Problem statement
Given a non-empty array of integers, return its second-largest distinct value.
Return -1 when the array contains fewer than two distinct values.
Examples
Inputa = [12, 7, 12, 4, 9]
Output9
The duplicate 12 is not a second distinct value.
Inputa = [4, 4, 4]
Output-1
No value exists below the largest distinct value.
The walkthrough is part of Premium
The statement and the examples above stay free. The full how-to-solve walkthrough, the cost notes in plain words and the interactive step-by-step visualizer unlock with a Premium plan.
See pricing