CIRCULAR LINKED LIST --doubt

link to ques: https://hack.codingblocks.com/contests/c/457/471

sir here when we are inputting the linked list then we cannot make use of normal insertion at the tail to build the list as it would make a copy of the elements being repeated and two nodes will be present with the same data…so how do we build the circular linked list while inputting

1 Like

You just keep taking inputs in the same manner as you did in the others(i.e. insertion at the tail) until you get an element which is already present in the list , in such case you need to check wheather the further elements are same if yess then point the last node to the matching node , else keep taking input .

https://ide.codingblocks.com/#/s/17550

sir one test case is giving run error

Actually this question is for inputs having no dublicates . So no need for so much calculation . just store alll the elements and start traversing the list until u get the element which has already occurred before.
https://ide.codingblocks.com/#/s/17565
:slight_smile:

sir but could you please check for mistake in my code…because all test cases are running except for one

Yeah ! Actually ur code is not working for :
1 2 3 4 5 6 2 3 2 3 -1
It’s kinda logical error .