can someone tell where i am doing the silly mistake?

Heres the question

Here is my solution

    import java.lang.*;
    import java.util.*;
    class universe
    public static void main(String args[])throws IOException
        BufferedReader br=new BufferedReader(new InputStreamReader(;
        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++)
           if(N==1 && st[1]=="Dee" && (s[0]%2)==0)

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


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


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?

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

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(;

  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