Circular Linked List question removal of loop

circular linked list question
two out of three test cases are failing
plz tell what is wrong in the approach
what can i do to correct it

problem - https://online.codingblocks.com/app/player/39658/content/37376/4967/code-challenge

code - https://ide.codingblocks.com/s/182330

Hi @sengarankit98

There is a small error in your code as it keeps on adding elements in the linked list even if it has detected a loop. For example: consider the case 1 2 3 4 5 4 7 -1, your program is giving the output as 1 2 3 4 5 7 whereas correct output is 1 2 3 4 5.
Hence you can declare a global variable flag = 0 and set it to 1 as soon as you find a repeated element. Then immediately stop taking the input and print the linked list. Your Code after correction : https://ide.codingblocks.com/s/182344.

Hope it Helps.
Give it a like, if you are satisfied. :slight_smile: