In this post, we will see how to find the second largest number in an array. Problem :Given an unsorted array, you need to find the second largest element in the array in o(n) time complexity. int[] arr1={7,5,6,1,4,2}; Solution:You can sort the array and then return second last element in the array but it will be done in o(nlogn) time, Algorithm:
Create the main java class named FindSecondLargestMain.java
Second largest element in the array : 6 That’s all about how to find second largest number in an array. Let us know if you liked the post. That’s the only way we can improve. |