Java lengthy double linked list solution beats 99.77% Time O(n) solution
\nclass FrontMiddleBackQueue {\n    \n    class ListNode{\n        int val;\n        ListNode next;\n        ListNode prev;\n        ListNode(int val){\n       
```\nclass FrontMiddleBackQueue {\n    \n    class ListNode{\n        int val;\n        ListNode next;\n        ListNode prev;\n        ListNode(int val){\n            this.val = val;\n        }\n    }\n    \n    int count;\n    ListNode start;\n    ListNode middle;\n    ListNode last;\n    \n    public FrontMiddleBackQueue() {\n        count = 0;\n        //place holders for start, middle, last\n        start = new ListNode(-1);\n        middle = new ListNode(-1);\n        last = new ListNode(-1);\n        \n        start.next = last;\n        last.prev = start;\n    }\n    \n    public void pushFront(int val) {\n        ListNode newNode = new ListNode(val);\n        \n        //insert new node in between start and start.next\n        newNode.next = start.next;\n        newNode.prev = start;\n        \n        //fix start and start.next to connect the new node\n        start.next.prev = newNode;\n        start.next = newNode;\n        \n        //increment count\n        count++;\n        if (count == 1)\n            middle = newNode;   // for first time the newNode will be the middle node\n        else if(count % 2 == 0) // if even store to the left side of existing middle node\n            middle = middle.prev;\n    }\n    \n    public void pushMiddle(int val) {\n        ListNode newNode = new ListNode(val);\n        \n        //if there is not extra node other than start and last then add the node to the middle\n        if (count == 0){\n            newNode.prev = start;\n            newNode.next = last;\n            \n            last.prev = newNode;\n            start.next = newNode;\n        }\n        else if(count % 2 == 0){   // if count is even then newNode will be pushed after middle\n            newNode.next = middle.next;\n            newNode.prev = middle;\n            \n            middle.next.prev = newNode;\n            middle.next = newNode;\n        }\n        else{\n            newNode.prev = middle.prev; // if count is odd then newNode will be pushed before middle\n            newNode.next = middle;\n            \n            middle.prev.next = newNode;\n            middle.prev = newNode;\n        }\n        middle = newNode;\n        count++;\n        return;\n    }\n    \n    public void pushBack(int val) {\n        ListNode newNode = new ListNode(val);\n        \n        // newNode will be inserted before the last\n        newNode.prev = last.prev;\n        newNode.next = last;\n        \n        last.prev.next = newNode;\n        last.prev = newNode;\n        \n        count++;\n        if (count == 1)\n            middle = newNode;\n        else if(count % 2 != 0) // if count is odd then middle will be set to the right side of new node\n            middle = middle.next;\n    }\n    \n    public int popFront() {\n        // no element to pop\n        if (count == 0)\n            return -1;\n        \n        int result = start.next.val;\n        //remove the start.next for pop operation\n        removeNode(start.next);\n        count--;\n        if (count % 2 != 0)\n            middle = middle.next;\n        \n        return result;\n    }\n    \n    public int popMiddle() {\n        // do only if there are elements\n        if (count == 0)\n            return -1;\n        \n        int result = middle.val;\n        removeNode(middle);\n        if (count % 2 != 0) // if count is odd then set middl to the left node\n            middle = middle.prev;\n        else\n            middle = middle.next; // if count is even then set middle to the right node\n        count--;\n        return result;\n    }\n    \n    public int popBack() {\n        // do only if there are elements\n        if (count == 0)\n            return -1;\n        \n        int result = last.prev.val;\n        //remove the last.prev node\n        removeNode(last.prev);\n        count--;\n        if (count % 2 == 0) // if count is even then set middle to the left node\n            middle = middle.prev;\n        return result;\n    }\n    \n    private void removeNode(ListNode node){\n        node.next.prev = node.prev;\n        node.prev.next = node.next;\n    }\n}\n```
['Doubly-Linked List', 'Java']