Search results
11 cze 2013 · function second_highest(arr) { var second_highest = arr.sort(function(a, b) { return b - a; })[1]; return second_highest; }
elif item > second_max and item < max: second_max = item. return -1 if second_max == float("-inf") else second_max. I saw this one on a Visa interview. int second = Integer.MIN_VALUE; for(int value : arr) { if(value > first) { second = first; first = value; } else if(value > second && value != first) { second = value; return second;
14 lis 2024 · Given an array of positive integers arr [] of size n, the task is to find second largest distinct element in the array. Note: If the second largest element does not exist, return -1. Examples: Explanation: The largest element of the array is 35 and the second largest element is 34.
12 lip 2024 · Finding the second largest element in an array in JavaScript involves sorting the array in descending order and then accessing the element at index 1. Alternatively, you can iterate through the array to identify the second-largest element manually. Examples: Output: The second largest element is 34. Output: The second largest element is 5.
13 mar 2024 · In this method, we traverse the linked list using the while loop, keeping track of the two largest numbers and printing the second largest number at the end. Example: The below code implements the iteration to find the second largest element in a linked list. Time Complexity: O (n) Space Complexity: O (1)
Second Largest Digit in a String - Given an alphanumeric string s, return the second largest numerical digit that appears in s, or -1 if it does not exist. An alphanumeric string is a string consisting of lowercase English letters and digits.
Can you solve this real interview question? Largest Number - Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.