Find Second Largest Number in an Array (Multiple Approaches)

preview_player
Показать описание
Given an array of integers, find second largest number in an array. In this tutorial, I have explained a java code to find second highest number in an array without using sorting.

The idea here is to find second largest number in an array using single loop in O(n) time complexity.

Рекомендации по теме
Комментарии
Автор

Inspired from you even I have started Sharing my Interview Experience with different Mnc's

DrunkenEngineer
Автор

how to print out two elements in the array if they are both the highest one?

cheenoong
Автор

Why you have assigned initial value of largest and second largest with min value

vijayalakshmipatil
Автор

Write Python program for finding the second largest element in an array A of size n using Tournament Method. Please give solutions

arunawaghmare
Автор

What if we have multiple values example 10 10 10 ??

M.m
Автор

i know there comes an extra space but what if i remove repeated array and put in separate array and check if len ==1 then no more second largest element else the second largest element will be a value away from largest element in sorted array

navarajpokharel
Автор

Hi ji, if (arr23[i]!=larges && arr23[i]>secondlargest) {

} what is the logic for this line, without using this also we are getting expected result

gurumurthys
Автор

2nd method doesn't work for negative numbers ..[0, -2, -7, -9]

anitareddy
Автор

how can we write this program without using Integer.MIN_VALUE can you plz ans it

omkarchikane