Fully Efficient Java Solution Explained
Intuition\nI applied the concepts of the given question using an array by shifting elements when needed.\n# Approach\nApproach given through the methods\n# Comp
# Intuition\nI applied the concepts of the given question using an array by shifting elements when needed.\n# Approach\nApproach given through the methods\n# Complexity\n- Time complexity:\n\n- Space complexity:\n\n# Code\n```\nclass FrontMiddleBackQueue {\n        int[] array;\n        int MAX_SIZE;\n        int numberOfElements;\n\n        public FrontMiddleBackQueue() {\n            array = new int[1000];\n            MAX_SIZE = 1000;\n            numberOfElements=0;\n        }\n\n        public void pushFront(int val) {\n            if (numberOfElements>=MAX_SIZE){\n                return;\n            }\n            //shifting all elements to free first place\n            for (int i = numberOfElements; i > 0; i--) {\n                array[i] = array[i-1];\n            }\n            array[0] = val;\n            numberOfElements++;\n        }\n\n        public void pushMiddle(int val) {\n            if (numberOfElements>=MAX_SIZE){\n                return;\n            }\n            int middle= numberOfElements/2;\n            //shifting second half to the right\n            for (int i=numberOfElements;i>middle;i--){\n                array[i] = array[i-1];\n            }\n            array[middle] = val;\n            numberOfElements++;\n        }\n\n        public void pushBack(int val) {\n            if (numberOfElements>=MAX_SIZE){\n                return;\n            }\n            array[numberOfElements++] = val;\n        }\n\n        public int popFront() {\n            if (numberOfElements==0){\n                return -1;\n            }\n            int element = array[0];\n            //shifting all the elements to the left\n            for (int i =0;i<numberOfElements;i++){\n                array[i] = array[i+1];\n            }\n            numberOfElements--;\n            return element;\n        }\n\n        public int popMiddle() {\n            if (numberOfElements==0){\n                return -1;\n            }\n            int middle = (numberOfElements-1)/2;\n            int element = array[middle];\n            //shifting back to their locations to the left\n            for (int i=middle;i<numberOfElements;i++){\n                array[i] = array[i+1];\n            }\n            array[numberOfElements-1] = 0;\n            numberOfElements--;\n            return element;\n        }\n\n        public int popBack() {\n            if (numberOfElements==0){\n                return -1;\n            }\n            int num = array[numberOfElements-1];\n            numberOfElements--;\n            array[numberOfElements] = 0;\n            return num;\n        }\n    }\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * FrontMiddleBackQueue obj = new FrontMiddleBackQueue();\n * obj.pushFront(val);\n * obj.pushMiddle(val);\n * obj.pushBack(val);\n * int param_4 = obj.popFront();\n * int param_5 = obj.popMiddle();\n * int param_6 = obj.popBack();\n */\n```
['Array', 'Design', 'Queue', 'Data Stream', 'Java']