Problem in solving COOMILK

I am trying to solve this problem https://www.codechef.com/problems/COOMILK … My solution is https://www.codechef.com/status/COOMILK,harshtrivedi12

What I am doing wrong here?

There are many things wrong with your code.

Firstly, your code prints “Yees” instead of “Yes”

Then, it fails on the sample input-

Input
4
7
cookie milk milk cookie milk cookie milk
5
cookie cookie milk milk milk
4
milk milk milk milk
1
cookie
Your Output
Yees
Yees
Yees
No
Expected Output
YES
NO
YES
NO

Although I am not familiar with java, I tried pointing out some mistakes.

Here are some of them:

1.You are looping through 0 to N-2 instead to N-1

2.You are printing Yees instead of YES.

3.Also, you are checking condition, whether N-1 string is a cookie or not which will overwrite flag value which is incorrect.Try to put them in if-else condition.

Here is my c++ code: https://www.codechef.com/viewsolution/14365556.

You can use it as the reference.

1 Like
//