[Solution][1]
→ Why does this code gives NZEC??
Thank You
[1]: CodeChef: Practical coding for everyone
[Solution][1]
→ Why does this code gives NZEC??
Thank You
[1]: CodeChef: Practical coding for everyone
adding an exception handler which does nothing removes the nzec error
java example:
try
{
} catch (Exception e){}
actually i use to code in python where there is no such use of return 0 statement.
I have submitted many problems in Python.
Then its due to some exception trace your source code carefully
my code is
import java.io.;
import java.lang.;
public class sum
{
public static void main (String[] args)throws Exception
{
java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
System.out.println(“Enter the number”);
int i=Integer.parseInt(r.readLine());
int sum=0;
for(int j=1;j<i;j++)
{
if(i%j==0)
{
sum+=j;
} }
System.out.println(sum);
}
}
But it is not showing any runtime error! What are you talking about? See-
If n>100 in your code , it will give you NZEC error
you can declare your array z dynamically or declare it with max value of n
Due to brute force consuming lot of memory in recursion calls and overflowing the memory stack. Use map data structure and memoization.
Thank you so much, i tried the memoization and got an AC.
can anyone tell me t=why NZEC error is there
solution
https://www.codechef.com/viewsolution/24654440
q
https://www.codechef.com/JUNE19/PROXYC
When i encountered NZEC problem, I found that I am using arraylist and adding values in it on basis of some condition and when condition is not fulfilled no value will be added in arraylist and in my next statements i was trying to access elements from empty arraylist which result into NZEC error, So while tracing your code keep in mind these things they may help you.
Please help me in the runtime error(NZEC)
code is as follows
process.stdin.resume();
process.stdin.setEncoding(‘utf8’);
var input = ‘’;
process.stdin.on(‘data’, function(chunk){
input += chunk;
})
process.stdin.on(‘end’, function(){
let array = input.split(’\n’);
// let testcases = parseInt(array[0])
for(let i = 1; i< array.length; i+= 2){
let candiesrequired = 0;
let thezoo = array[i].split(' ')
let candiesavailable = parseInt(thezoo[1]);
let hathi = parseInt(thezoo[0]);
let eachrequirement = array[i + 1].split(' ')
for(let j = 0; j < hathi; j++){
candiesrequired += parseInt(eachrequirement[j])
}
if(candiesavailable >= candiesrequired){
console.log('Yes')
}
else{
console.log('No')
}
}
})