Getting WA (MISSP)

Hello guys,

Here’s the problem’s link.
Here’s my code in java

import java.util.*;
class ChefandDolls
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
int T=in.nextInt();
while(T-- > 0)
{
int N=in.nextInt();
int[] Ns=new int[N];
for(int i=0 ; i<N ; i++)
Ns[i]=in.nextInt();

        Arrays.sort(Ns);
        
        for(int i=0 ; i<N ; i+=2)
        {
            try
            {
                if(Ns[i]!=Ns[i+1])
                {
                    System.out.println(Ns[i]);
                    return;
                }
            }
            catch(ArrayIndexOutOfBoundsException e)
            {
                System.out.println(Ns[i]);
            }
        }
    }
}

}

But this code get WA, for some reason that I badly want to know
Please Help!:innocent:

Consider the testcase:

2
5
1 1 2 3 3
5
1 1 2 3 3
1 Like

But it gives correct answer as 2

How many testcases are there?

1 Like

Oh! damn! Now I understood the problem is with the return statement, actually the whole program terminates not just the loop, so it prints the answer for only one test case, should use break instead.

Thanks Bro!
Thanks for helping!

1 Like