📌📌 C++ || Math || Two Pointer || Faster || Easy To Understand
Math\n\n Time Complexity :- O(N)\n\n Space Complexity :- O(Constant)\n\n\nclass Solution {\npublic:\n    vector<int> addToArrayForm(vector<int>& num, int k) {\n
* ***Math***\n\n* ***Time Complexity :- O(N)***\n\n* ***Space Complexity :- O(Constant)***\n\n```\nclass Solution {\npublic:\n    vector<int> addToArrayForm(vector<int>& num, int k) {\n        \n        int n = num.size();\n        \n        // convert the k into string\n        \n        string str = to_string(k);\n        \n        int m = str.size();\n        \n        // intitialize i and j\n        \n        int i = n - 1, j = m - 1;\n        \n        int carry = 0;\n        \n        vector<int> res;\n        \n        // start traversing from right side\n        \n        while(i >= 0 || j >= 0 || carry)\n        {\n            // find sum\n            \n            int sum = 0;\n            \n            if(i >= 0)\n            {\n                sum += num[i];\n            }\n            \n            if(j >= 0)\n            {\n                sum += str[j] - \'0\';\n            }\n            \n            sum += carry;\n            \n            // update the carry\n            \n            carry = sum / 10;\n            \n            // push the digit into res\n            \n            res.push_back(sum % 10);\n            \n            // update pointers\n            \n            i--;\n            \n            j--;\n        }\n        \n        // reverse the res\n        \n        reverse(res.begin(), res.end());\n        \n        return res;\n    }\n};\n```
['Math', 'C', 'C++']