Java | Algo explained | beats 100% time
\nEXPLANATION:-\nGiven a list  1 ->  2 -> 3 -> 4 -> 5\nNow we need to reorder it like 1 -> 5 -> 2 -> 4 -> 3\n\nHow can we do this?\nconsider list elements as L1
```\nEXPLANATION:-\nGiven a list  1 ->  2 -> 3 -> 4 -> 5\nNow we need to reorder it like 1 -> 5 -> 2 -> 4 -> 3\n\nHow can we do this?\nconsider list elements as L1, L2, .... , Ln-1, Ln.\nwe need \nL1 -> Ln -> L2 -> Ln-1 -> . . .\nNow, if we maintain a pointer at each end, \nthen we can arrange them alternatively.\nleft = L1, right = Ln\nNow 1st iteration\nList => L1 -> Ln\n\n2nd iteration\nleft = L2, right = Ln-1\nList => L1 -> Ln -> L2 -> Ln-1\n\n3rd iteration\nleft = l3, right = Ln-2\nThis process continues until all elements are processed.\n\nHere, the problem is if we maintain a pointer at last element in the list\nwe can\'t move to it\'s previous element after \nit is processed since it is single linked list.\n\nSo, to do this, we split the list in two halves and \nreverse the second half.\nList = 1 -> 2 -> 3 > 4 -> 5\nAfter splitting:-\nL1 = 1 -> 2\nL2 = 3 -> 4 -> 5\nNow, we need to reverse second list\nSo, L2 = 5 -> 4 -> 3\n\nNow, insert each element in 2 lists alternatively.\n1 -> 5 -> 2 -> 4 -> 3\n\nThis is how we can get the result.\n\nIF YOU HAVE ANY DOUBTS, FEEL FREE TO ASK.\nIF YOU UNDERSTAND, DON\'T FORGET TO UPVOTE.\n\n\n```\n```\nclass Solution {\n    public ListNode reverse(ListNode head){\n        ListNode p1 = head;\n        ListNode p2 = head.next;\n        p1.next = null;\n        while(p2 != null){\n            ListNode temp = p2.next;\n            p2.next = p1;\n            p1 = p2;\n            p2 = temp;\n        }\n        return p1;\n    }\n    public void reorderList(ListNode head) {\n        if(head == null || head.next == null) return ;\n        ListNode slowPtr = head, fastPtr = head;\n        ListNode prev = head;\n\t\t// splitting list\n        while(fastPtr != null && fastPtr.next != null){\n            prev = slowPtr;\n            slowPtr = slowPtr.next;\n            fastPtr = fastPtr.next.next;\n        }\n        prev.next = null;\n\t\t// reverse\n        ListNode rev = reverse(slowPtr);\n        ListNode ptr = head;\n\t\t// arrange alternatively\n        while(ptr != null){\n            ListNode t1 = ptr.next;\n            ListNode t2 = rev.next;\n            ptr.next = rev;\n            if(t1 != null)\n                rev.next = t1;\n            ptr = t1;\n            rev = t2;\n        }\n    }\n}\n```\n\nI have started a series on solid principles and design patterns. If anyone is interested, please check [it](https://medium.com/@bhanu150138/mastering-solid-principles-and-design-patterns-a-blog-series-for-writing-clean-scalable-code-aae3809310db) out.
['Linked List', 'Two Pointers', 'Stack', 'Recursion']