• + 0 comments
    function getSecondLargest(nums) {
        let first = -Infinity, second = -Infinity;
        
        for (let i = 0; i < nums.length; i++) {
            if (nums[i] > first) {
                second = first;
                first = nums[i];
            } else if (nums[i] > second && nums[i] < first) {
                second = nums[i];
            }
        }
        
        return second;
    }