# Second Largest Codechef Solution

#### ByBrokenprogrammers

Dec 4, 2022

Hello Programmers In this post, you will know how to solve the Second Largest Codechef Solution.

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

### Problem

Three numbers AB and C are the inputs. Write a program to find second largest among them.

### Input

The first line contains an integer T, the total number of testcases. Then T lines follow, each line contains three integers AB and C.

### Output

For each test case, display the second largest among AB and C, in a new line.

### Constraints

• 1 <= T <= 1000
• 1 <= A, B, C <= 1000000

Input:

```3
120 11 400
10213 312 10
10 3 450
```

Output:

```120
312
10```

### Second Largest CodeChef Solutions in Python

```N = int(input())
for i in range(N):
x = list(map(int, input().split()))
x.sort()
print(x[1])```

### Second Largest CodeChef Solutions in CPP

```#include <iostream>
using namespace std;
int main(){
int a;
cin >> a;
while(a--){
long long a,b,c;
cin >> a >> b >> c;
if(a>=b && b>=c || a<=b && b<=c)
cout << b << endl;
else if(a>=c && c>=b || a<=c && b>=c)
cout << c << endl;
else
cout << a << endl;
}
}```

### Second Largest CodeChef Solutions in JAVA

```import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int tc = 0; tc < T; tc++) {
int A = sc.nextInt();
int B = sc.nextInt();
int C = sc.nextInt();
System.out.println(solve(A, B, C));
}
sc.close();
}
static int solve(int A, int B, int C) {
return Arrays.asList(A, B, C).stream().sorted().collect(Collectors.toList()).get(1);
}
}```

Disclaimer: The above Problem (Second Largest) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.