×
Take two variables and initiliaze them with zero. Iterate through each element of the array and compare each number against these two number. If current number is greater than maxOne then maxOne = number and maxTwo = maxOne. Otherwise if it only greater than maxTwo then we only update maxTwo with current number.
Jan 1, 2018
People also ask
Mar 10, 2018 · This can be achieved via Arrays.sort() or Collection.sort() and once the given array is sorted the second largest number can be easily found.
May 11, 2020 · Given an array of huge numbers of elements, find the Kth largest element. For example, in the given array below, the 3rd largest would be 10.
Feb 15, 2020 · The trick to find the missing number is using the mathematical formula of Sum of Series to find the sum of N numbers and then subtract it from ...
Sep 11, 2018 · That is, you first sort the array. And then you traverse all elements to find the max-element. First, you wanted to find the second to max ...
Missing: devglan | Show results with:devglan
Jun 20, 2020 · Write a Java program to find the largest sum of the contiguous subarray in a given Array. The given array might contain negative elements ...
In many java interviews especially for freshers, it is asked to write program to find max two numbers from a given array.This kind of program is good to check ...
Jun 5, 2021 · iterate over array using a for loop and find index of maximum number. Once you have it do int maxDrop = a[maxIndex] - a[maxIndex-1]; The time ...
Missing: devglan | Show results with:devglan
Jan 1, 2018 · Java interview program to find middle index of an array where both ends sum is equal i.e. the sum of numbers preceding the index is equals ...