Testcase 2 run error

my code is https://ide.codingblocks.com/s/111864
test case 2 is showing run error please tell the reason.
In the question Circular linked list the SAMPLE INPUT is
1 2 3 4 5 2 3 -1 so the circular list the cycle is not repeating from 1 its repeatig from 2 . so how to solve this problem

@vaibhavgupta.1919
I have correct the null pointer exception,As ref was pointing to null just added ref!=null in the while condition.


I hope you understands your approach is wrong,it will give correct answer only when the cycle starts from the beginning of the loop.
Consider 1 2 3 4 5 2 3 -1 the loop starts from 2,how will your code tackle this out.
For this we need to know standard Algorithm Flyodd Warshall loop detection Algorithm.

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.