Given an array of integers, return the second largest value.
Example:
Input: nums = [2, 7, 11, 8, 11, 8, 3, 11]
Output: 8
Explanation: The maximum value is 11. The second largest value is 8.
Note:
You may assume the array contains at least two distinct values.
Follow up:
Could you solve this in one pass without sorting?
Walkthroughs of the solution. Try the steps first, then watch to compare approaches.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check