@ayushagrawal07

In your code, the code block used below will only correctly worked for an array sorted in ascending order, but in the problem statement we might or might not get pre-arranged values.

Consider the values being *(1, 2, 3)*. Here, after final iteration, we will get *(max=3)* and *(max2=2)* and the answer will be correct.

But if the values were like, *(3, 1, 2)*. Here,

- After first iteration, we get
*(max=3)* and *(max2=0)*.
- After second iteration,
*(max=3)* and *(max2=0)*, as *A[i]* will be lesser than *max*.

*Same happens in third iteration.

Finally we have, *(max=3)* and *(max2=0)*, which will be incorrect.

You could either sort the array before finding *max* and *max2* and the code should work fine.

```
for(int i=0;i<n;i++)
{
if(arr[i] >= max)
{
max2 = max;
max = arr[i];
}
}
```

The logic I used to solve the problem was like this.

We are provided with three number and have to find the sum of largest two from them.

The problem can also be changed as finding the sum of all three and subtracting the smallest of three.

Here is my code for reference.

```
# cook your dish here
for _ in range(int(input())):
a,b,c=map(int,input().split())
print((a+b+c)-min(a,b,c))
```