Delete every ‘t’th (t>1) node of a single linked list. In the resultant linked list, again delete ‘t’th node. Repeat this till only t-1 nodes remains.
For this i have come up with:
Traverse until you reach ‘t’th node, delete all the nodes till the end.
Is there any efficient way other than this?. Can any one please help me out. Thanks.
This wording of the question is rather bizarre because what is the point of repeatedly deleting t’th elements when at the end you’re just left with t-1 nodes? Is this a homework question? Are you sure you’ve understood it correctly? If the question is indeed correct and all you care about is the end result, then doing what you’ve said — deleting all nodes from t to the end, is indeed the most efficient way. The only thing to consider is that the question specifies a certain order of deleting items, and you are disregarding that order.