MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / FirstThreeLargest

Class FirstThreeLargest

FirstThreeLargest.java:1–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1public class FirstThreeLargest{
2 public static void Main(String args[])
3 {
4 int arr[] = {2,7,9,3,6,1,11,8};
5 solve(arr);
6 }
7 public static void solve(int arr[])
8 {
9 int n=arr.length;
10 int first = Integer.MIN_VALUE, second=Integer.MIN_VALUE,third=Integer.MIN_VALUE;
11 for(int i=0;i<n;i++)
12 {
13 if(first<=arr[i])
14 {
15 third = second;
16 second = first;
17 first = arr[i];
18 }
19 else if(second<=arr[i])
20 {
21 third = second;
22 second = arr[i];
23 }
24 else if(third<=arr[i])
25 {
26 third = arr[i];
27 }
28 }
29 System.out.println(first + " " + second + " "+ third);
30 }
31}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected