Help me with the run error in the below code. I checked the logic but couldn’t find the cause for it. Placed a check for empty stack.
Getting run error
Okay I will check for errors and get back to you
Hey actually this code’s inputs are wrong. It says first line as integer containing number of functions. However 2 integers are present in the first line. Raise this question to the support team
can you give me list of test cases quickly
?
you can check the sample test case which is wrong. Others are the same way.
2 4 (error)
0:start:0
1:start:2
1:end:5
0:end:6
I have changed the input format now. One test case is failing still. It means there is some issue with the logic. Let me know where it is going wrong.
What error are you getting now? WA or TLE
if(!stack.isEmpty())
{ time[Integer.parseInt(stack.peek())] = time[Integer.parseInt(stack.peek())] + Integer.parseInt(timeCount)+1;
}
This portion of the code is wrong leading to error.
For the input’
2 4
0:start:0
1:start:3
1:end:56
0:end:90
the output is 37 54
However your answer is coming out as 31 54 and your stackt trace after each operation as
3
54
60
31
basically you are adding where you should be subtracting
change the + to - in this as
time[Integer.parseInt(stack.peek())] = Integer.parseInt(timeCount) - time[Integer.parseInt(stack.peek())]+1;
Thanks Abhinav for the help. Got the error.