✔C++|Very Easy | Beats 100%  | O(n) |✔
Intuition\n Describe your first thoughts on how to solve this problem. \nSimply just transform k into an array for easy traversal then just take care of carry a
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSimply just transform k into an array for easy traversal then just take care of carry and take the sum of nums vector and kth vector .\n- We can avoid using the vector for k by just taking directly elements from k .\n- Below are given the  two implementations :\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:$$O(max(n,logK))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(max(n,logK))$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> addToArrayForm(vector<int>& arr, int k) {\n        vector<int>ans;\n        vector<int>v;\n        while(k>0){\n            v.push_back(k%10);\n            k/=10;\n        }\n        reverse(begin(v),end(v));\n        int n=arr.size();\n        int carry=0;\n        int i=n-1,j=v.size()-1;\n        while(i>=0 or j>=0){\n            int sum=carry;\n          if(i>=0)sum+=arr[i--];\n          if(j>=0)sum+=v[j--];\n          carry=sum/10;\n          ans.push_back(sum%10);\n        }\n        if(carry)\n        ans.push_back(carry);\n         reverse(begin(ans),end(ans));\n        return ans;\n    }\n};\n```\n**Wihtout using a vector for k**\n```\nvector<int> addToArrayForm(vector<int>& arr, int k) {\n        vector<int>ans;\n        int i=arr.size()-1;\n        int carry=0;\n       while(k>0 or i>=0){\n           int sum=carry;\n           if(i>=0)sum+=arr[i--];\n           sum+=k%10;\n           carry=sum/10;\n           k/=10;\n           ans.push_back(sum%10);\n       }\n       if(carry)ans.push_back(carry);\n       reverse(ans.begin(),ans.end());\n        return ans;\n    }\n```
['Array', 'Math', 'Number Theory', 'C++']