Given an array of at least two integers nums, return the second largest distinct value. If every value is equal, return that value.
Second Largest Value (Set 2) — the data. This set runs 4 cases: nums holds arrays of 8–18 items, with values from -19 to 24. The hidden cases are the largest of the set.
Example 1
secondLargestValue()
Input
nums =[13,12,14,-14,23,-6,11,8]
Output
14
Why
`secondLargestValue` returns `14`forthisinput.
Example 2
secondLargestValue()
Input
nums =[-9,24,-14,-12,23,15,16,-14,8]
Output
23
Why
`secondLargestValue` returns `23`forthisinput.
Constraints
2<=nums.length<=10^5-10^5<= nums[i]<=10^5
Every caseinthisset must pass: the first two are visible on Run, the last two unlock on Submit.
Topics
Arrays
Implement secondLargestValue in the editor and return the answer — printing it is never graded.