✅ For N base characters and beyond | 🔰 O(n) Time and O(n) space❗️
Intuition\nThis problem is similar to problem: 67. Add Binary. You should try and solve that problem first. If you are still confused, see the below solution.\n
# Intuition\nThis problem is similar to problem: [67. Add Binary](https://leetcode.com/problems/add-binary/). You should try and solve that problem first. If you are still confused, see the below solution.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nMy solution to [67. Add Binary](https://leetcode.com/problems/add-binary/)  => [https://leetcode.com/problems/add-binary/solutions/3186596/have-you-thought-this-way-beats-100-self-explanatory-code/](https://leetcode.com/problems/add-binary/solutions/3186596/have-you-thought-this-way-beats-100-self-explanatory-code/)\n\n![3549-pepepopcorn.png](https://assets.leetcode.com/users/images/ae3f7606-e894-4cd9-8ec8-79ed937375ed_1676439722.7051065.png)\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nAs you have learned basic summation by hand. You probably have an idea about the **carry**. In this solution we will also need to keep and store **carry** in a variable. You probably start from the right then calculate to the left.\n\nLet\'s see for an example:\n```\nnum = [2,1,5], k = 806\n```\n\n| carry | num1 from k | num2 from num[] | sum | add to list | updated carry |\n|-------|------|------|-----|-----|-----|\n|0 | 6 | 5 | 11 | 1 | 1 |\n|1 | 0 | 1 | 2 | 2 | 0 |\n|0 | 8 | 2 | 10 | 0 | 1 |\n|1 | 0 | 0 | 1 | 1 | 0 |\n\nTo find the last digit from k, we will do k%10. As this is a 10 base number, we need to mod 10. If this was 2 base (binary) or 8 base (octal) number then we need to do k%2 or k%8 respectively.\nAfter doing that, we update k by doing k/10. This means we are erasing the last digit. Again, as it is 10 base number we are using 10. For 2 or 8 base number we will use 2 or 8.\n\nWe iterate the loop of the array. After the iteration is complete, we check if k is 0. If it is not, we further add the values from k.\n\nLastly, an important part is, whether carry is 0 or not. If it is not 0, we must add that to the list.\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\nWe are declaring another list to store the output.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code [Java]\n```\nclass Solution {\n    public List<Integer> addToArrayForm(int[] num, int k) {\n        List<Integer> list = new LinkedList<>();\n        int carry = 0;\n        for(int i=num.length-1; i>=0; i--){\n            int num1 = 0;\n            if(k!=0){\n                num1 = k%10;\n                k/=10;\n            }\n            int num2 = num[i];\n            int sum = carry + num1 + num2;\n            carry = sum/10;\n            list.add(sum%10);\n        }\n        while(k!=0){\n            int sum = carry + k%10;\n            k/=10;\n            carry = sum/10;\n            list.add(sum%10);\n        }\n        if(carry!=0){\n            list.add(carry);\n        }\n        Collections.reverse(list);\n        return list;\n    }\n}\n```\n\n![No Upvotes, Have a Good Day.png](https://assets.leetcode.com/users/images/7211cfa9-b625-4ca0-bdd0-32a8b8e5e10c_1676440010.2570288.png)\n
['Java']