Circular Linked List question in java

im getting a timed out error , for this code, kindly help me identify the mistake.

Hi Aman
Your code doesn’t work for the case 1 -1. The output should 1 in this case. Your code gives null pointer exception.

Also, there is no need to take input in a string. You can take input normally in the form of integers.

int a;
do {
a = scn.nextInt();
l.addLast(a);

} while (a != -1);

yes i made the change, but it is still showing timed-out for 2 test cases

Hi @justformyntra8

Can you share the link to your modified code? I’ll have a look once.

Hi Aman
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.
Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

I have shared the updated code- please let me know where I am mistaken

Hi @justformyntra8

The complexity of the question is very high. That is why you are getting Time Limit Exceeded error.
Try implementing a different approach.

Hi @justformyntra8

As you are not responding to the thread, I am marking your doubt as resolved for now. Re-open it if required.
Please mark your doubt as resolved in your course’s “Ask Doubt” section, when your doubt is resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.