
Asked in Adobe and 43 others
Given an array of integers, find the second largest element.

AnswerBot
13d
Find the second largest element in an array of integers efficiently.
Iterate through the array while keeping track of the largest and second largest elements.
Initialize two variables, 'largest' and 'se...read more
Anonymous
5mo
System.out.println(" Printing the second largest value: "+
arr.stream().distinct().sorted().toList().get(arr.size()-2));
Geethika Kodidela
2y
Package com.candidjava;
public class SecondLargest
{
public static void main(String[] args)
{
int arr[] = { 14, 46, 47, 86, 92, 52, 48, 36, 66, 85 };
int largest = arr[0];
int secondLargest = arr[0];
System.o...read more
Anonymous
2y
Sort the array and print the second last element.
Add answer anonymously...
Interview Questions from Popular Companies

3.7
• 8.8k Interviews

4.0
• 5.5k Interviews

3.4
• 4.2k Interviews

3.5
• 8k Interviews

3.7
• 6k Interviews

3.7
• 6.2k Interviews

3.5
• 4.2k Interviews

3.7
• 5.1k Interviews
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

