/ package codechef; // don't place package name! /
} Its showing runtime error NZEC. Can someone please check my code? i'm new to codechef. asked 19 Jul '17, 20:22

The problem link is https://www.codechef.com/problems/CONFLIP . You are getting NZEC (which means runtime error) because the max input value for N (here rounds) is 10^9 . You are therefore trying to create an array with 10^9 elements, which is not allowed in java. The max number of elements that the compiler will allow is 10^9, but in reality, whenever the number of elements is > around 4.4*10^7, java will give a runtime error. So, try to limit the number of elements in an array to 10^7. Hope that answered your question. :) I would also suggest you take a look at this  http://www.geeksforgeeks.org/fastioinjavaincompetitiveprogramming/ answered 20 Jul '17, 01:23

In this problem, you don't even need to create an array. It's a very simple logic Let's say we have N number of rounds to be an even number. For example  4 Now we know either they all have to be tail or head. Let's say we have head {H H H H} Now the logic is if we have N to be even number, we divide it by 2 which is The answer will be (N/2) So the above head will end up be {H T H T} so when we have an even number of rounds and coins, it doesn't matter if the coin is head or tail The problem comes up when we have odd numbers of rounds and coins. For example, we have 5 number of rounds and coin. This time let's say we have tail {T T T T T} Now the result will be {H T H T H} and we need to find the number of tails in the result Here's the logic if the given coins are the tail and an odd number of coins and rounds. The result will be (N/2)+1 if we're finding the same coin in the result as the coin given in the question. if we had to find the Head in the above question then we simply do (N/2). I hope that helps, you can check out my solution for this problem. https://www.codechef.com/viewsolution/14531353 answered 20 Jul '17, 03:23
2
He knows this. See his submissions. He asked this question after successfully submitting using the correct logic. He just wanted to know what was wrong with his above approach.
(20 Jul '17, 15:24)

Give the problem link as well please. Its not possible to judge a solution before knowing the question.