Skip to main content

Find the largest and second largest element in an array

Given an array which includes integer elements. Our goal is to find the largest and 2nd largest element which are present in given array. For example.

Example A
arr1[] = {10 , 3 , 23 , 86 , 8 , 9 , 44 , 5 , 7}
                        ⇧            ⇧
--------------------
First Largest   : 86
Second Largest  : 44

Example B
arr2[] = {10 , 3 , 11 , 16 , 8 , 16 , 5 , 9 , 7}
                        ⇧         ⇧
--------------------
First Largest   : 16
Second Largest  : 16

Example C
arr3[] = { 10 }
--------------------
None
(Because less than 2 element)

Here given code implementation process.





Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment