Question: https://online.codingblocks.com/app/player/69347/content/128054/4860/code-challenge
mysolution: https://ide.codingblocks.com/s/300950
Query:
I soled this question via a doubly linked list and 2 pointer approach . I want to know that how can i optimize this approach using doubly linked lists ( without the use of STL file of linked list or any other headerfiles etc ).
Also , can you please provide the solution for this question via a singly linkedlist approach , if my algo using singly link list is not proper or if there’s any better approch other than this one:
- Break the list in 2 parts i.e. List 1 (from head till mid) and List 2(from mid->next node till tail).
2.Then traverse list 1 from left to right using a pointer and traversing list 2 from left to right-1 times in every iteration using a temp pointer since it’s a singly linked list and then comparing the data of both of these lists .