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 1) — the data. This set runs 4 cases: nums holds arrays of 3–10 items, with values from -20 to 21. The hidden cases are the largest of the set.
Example 1
secondLargestValue()
Input
nums =[-4,-20,19,16]
Output
16
Why
`secondLargestValue` returns `16`forthisinput.
Example 2
secondLargestValue()
Input
nums =[21,2,14]
Output
14
Why
`secondLargestValue` returns `14`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.