×
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 5, 2013 · I am attempting to return the two largest integers from my int array. I am able to return the largest and the smallest fine, but I cannot get my ...
Missing: devglan | Show results with:devglan
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.
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 ...
Sep 11, 2018 · 3 Answers. we need to sort an array on descending order you can use bubble sort, now we can get the last index value as highest number and ...
Missing: devglan | Show results with:devglan
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 ...
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 ...
Jul 12, 2023 · The idea is to iterate over all the possible pairs and calculate the AND value of those all. and pick the largest value among them.
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 ...