Second Largest in Array — C++ Coding Problem
Difficulty: easy | Category: array
Problem Description
Given an array of integers `nums`, return the second largest distinct value in the array. If no second largest exists (e.g. all elements are the same, or the array has fewer than 2 elements), return `-1`.
Examples
Example 1
Input: nums = [3, 1, 4, 1, 5, 9, 2, 6]
Output: 6
Example 2
Input: nums = [1, 1, 1]
Output: -1
Example 3
Input: nums = [10, 5]
Output: 5