Java | 100% Faster | Stack Approach | LIFO
Intuition  : As all we know stacks are "last in first out", so we use this method to store remainders in a Stack and get all elements from the stack to ArrayLis
**Intuition  :** As all we know stacks are "last in first out", so we use this method to store remainders in a Stack and get all elements from the stack to ArrayList so that it follows the order. Sorry for my bad english !\n\n**Alogithm  :**\n```\n1. Create empty Stack and one List.\n2. Traverse the nums array and store all the digits of every number into the Stack.\n3. pop() every element from the Stack to List, now the elements are storing in reverse order into the List as exactly what we need.\n4. after iteration create answer array which length equals to size of List, and traverse through List and add elements to answer array\n5. return final array.\n```\n\n**Java Code :**\n```\nclass Solution {\n    public int[] separateDigits(int[] nums) {\n        \n        Stack<Integer> stack = new Stack<>();\n        ArrayList<Integer> list = new ArrayList<>();\n\n        for (int x : nums) {\n\n            while (x > 0) {\n                int rem = x % 10;\n                stack.push(rem);\n                x /= 10;\n            }\n            \n            while (!stack.isEmpty()) {\n                list.add(stack.pop());\n            }\n        }\n\n        int index = 0;\n        int[] ans = new int[list.size()];\n\n        for (int i = 0; i < list.size(); i++) {\n            ans[index++] = list.get(i);\n        }\n        return ans;\n    }\n}\n```\n\n**Time Complexity : O(N)\nSpace Complexity : O(N)**
['Stack', 'Java']