can someone tell where i am doing the silly mistake?

Heres the question

Here is my solution

 import java.io.*;
    import java.lang.*;
    import java.util.*;
 
    import javax.net.ssl.ExtendedSSLSession;
 
    class universe
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int T=Integer.parseInt(br.readLine());
        for(int j=0;j<T;j++)
        {
            String[] st=br.readLine().split(" ");
           int N= Integer.parseInt(st[0]);
           int[]s=new int[N];
           String[] sb= br.readLine().split(" ");
           for(int i=0;i<N;i++)
           s[i]=Integer.parseInt(sb[i]);
           if(N==1 && st[1]=="Dee" && (s[0]%2)==0)
           System.out.println("Dee");
           else
           System.out.println("Dum");
        }
    }
} 

Your logic is incorrect. According to your code, for all the values of n other than 1, the output will be Dum only. This is not correct. For instance, the following cases will give wrong answer with your code.

2 Dee
1 1 Output: Dee

2 Dum
1 1 Output: Dee

1 Like

Sir, youā€™re not even going through the array

             if(N==1 && st[1]=="Dee" && (s[0]%2)==0)

Look at this part

               s[0]%2

Why only the first element? You should be going through the whole array. You should have a for loop to go through the array and check who will win in the end

@therisingsun

sir, one person at a time can pick up only from a single heap, and in both your test cases, dee(even person) cant pick up any element from any heap, so its sure to loose.
but my problem is not that, actualy the problem even if the condition

ā€™ [if(N==1 && st[1]==ā€œDeeā€ && (s[0]%2)==0)]

is satisfied, its printing dum and not ā€œdeeā€? i am not able to understand why?

@kunnu120
please tell me, why even when your above mentioned condition, i.e
if(N==1 && st[1]==ā€œDeeā€ && (s[0]%2)==0)
is satisfied, even then program is printing ā€œdumā€ and not ā€œdeeā€ ?

Sorry, i misread the question.
You are saying that even if the condition is satisfied , its not printing ā€œdeeā€. This is because your condition never gets satisfied.
You are using st[1]==ā€œDeeā€. Here ā€˜==ā€™ indicates equating the addresses of st[1] and string literal ā€œDeeā€, and their addresses are different. Try using equals() method. This method equates the value.

1 Like

Letā€™ say we have input

1
3 Dee
2 3 2

The right answer will be Dee as for the first try Dee will eat the first even number (which is a[0] =2) and then itā€™s time for Dum, he will eat the maximum number of odd stones, so he can win. So, now he will eat those 3 stones(which is a[1]=3) and now itā€™s time for Dee he will eat the even number of stones. which is (a[2]=2). So, the winner should be Dee but your answer printing Dum. Youā€™re saying that if N is not equal to 1 then Dum will always win. And for the string compare, to check if strings are equal, you should be doing NameOfTheString.equals(ā€œtheNameYouAreComparingWithā€). Try using a for loop so you can play with every element of the integer. I will not tell you the solution, as I can see youā€™re a good coder, but youā€™re overcomplicating things as I find Buffereader tough to start with youā€™re taking the input in a very complicated way.

You could have

public static void main(String[] args)

{

public class universe 

{

  Scanner input = new Scanner(System.in);

  int T = input.nextInt();

  for(int i = 0;i<T;i++)

{

   int sizeOfTheArray = input.nextInt();

  int[] array = new int[sizeOfTheArray);

    String name = input.nextLine();


  for(int k = 0; k<sizeOfTheArray;k++)

   {

      array[k] = input.nextInt();

   }

If you still have problem, please ask!! Just donā€™t over-complicate this question