My issue
How to start writing code inside codechef, i come from Leetcode. How Can i know what i have to take form user ?? Please give me code of this Question for understanding the writing way in codechef.
My code
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
}
}
Learning course: Arrays, Strings & Sorting
Problem Link: Chef and Dolls Practice Problem in - CodeChef
@ajaymahiwal
plzz refer the following solution for better understanding
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner scn=new Scanner(System.in);
int t=scn.nextInt();
while(t-->0)
{
int n=scn.nextInt();
int doll[]=new int[n];
for( int i=0;i<n;i++)
{
doll[i]=scn.nextInt();
}
Arrays.sort(doll);
int k=check(doll,n);
System.out.println(k);
}
}
public static int check(int[] doll,int n )
{
for (int i=0;i<n-2;i+=2)
{
if ((doll[i]!=doll[i+1]))
{ // i=i+2;
return doll[i];
}
}
return doll[n-1];
//return 0;
}
}