C++ || using two deque's beats 99.53%  || commented
\nclass FrontMiddleBackQueue {\npublic:\n    //we can make use of two deque \n    //first deque >= second deque number of elements\n    deque<int> first;\n    d
```\nclass FrontMiddleBackQueue {\npublic:\n    //we can make use of two deque \n    //first deque >= second deque number of elements\n    deque<int> first;\n    deque<int> last;\n    FrontMiddleBackQueue() {\n        \n    }\n    \n    void pushFront(int val) {\n        //push to the first deque\n        first.push_front(val);\n        if(first.size()-1>last.size())\n        {\n            //we need to transfer some elemnts to last deque\n            int end=first.back();\n            first.pop_back();\n            last.push_front(end);\n        }\n    }\n    \n    void pushMiddle(int val) {\n        //add ele to the back of first deque\n        if(first.size()>last.size())\n        {\n            int end=first.back();\n            first.pop_back();\n            last.push_front(end);\n        }\n        first.push_back(val);\n    }\n    \n    void pushBack(int val) {\n        last.push_back(val);\n        if(last.size()>first.size())\n        {\n            //we need to transfer some elements to the first deque\n            int front=last.front();\n            last.pop_front();\n            first.push_back(front);\n        }\n    }\n    \n    int popFront() {\n        if(first.size()==0)\n            return -1;\n        int val=first.front();\n        first.pop_front();\n        if(first.size()<last.size())\n        {\n            int front=last.front();\n            last.pop_front();\n            first.push_back(front);\n        }\n        return val;\n    }\n    \n    int popMiddle() {\n        //middle always lies at the back of first deque\n        if(first.size()==0)\n            return -1;\n        int val=first.back();\n        first.pop_back();\n        if(first.size()<last.size())\n        {\n            int front=last.front();\n            last.pop_front();\n            first.push_back(front);\n        }\n        return val;\n    }\n    \n    int popBack() {\n        if(last.size()==0)\n        {\n            //we need to pop the first \n            if(first.size()==0)\n                return -1;\n            int val=first.back();\n            first.pop_back();\n            return val;\n        }\n        //if last is not empty\n        int val=last.back();\n        last.pop_back();\n        if(first.size()-1>last.size())\n        {\n            //we need to transfer some elemnts to last deque\n            int end=first.back();\n            first.pop_back();\n            last.push_front(end);\n        }\n        return val;\n    }\n};\n```\n\n**Please upvote if this helps :)**
[]