JavaScript Solution with Full Explanation
Please upvote if you find the solution helpful.\n\n\nvar addToArrayForm = function(num, k) {\n\n    let i = num.length - 1;\n    let res = [];\n    while(i >= 0
*Please upvote if you find the solution helpful.*\n\n```\nvar addToArrayForm = function(num, k) {\n\n    let i = num.length - 1;\n    let res = [];\n    while(i >= 0 || k >0 ){\n\t\t//this is the general check : taking the last elemnt and adding it with the k value then take the carry(if any to the next iteration) \n        if(i >= 0){\n            res.push((num[i] + k) % 10);\n            k = Math.trunc((num[i] + k) / 10);\n\t\t\ti--;\t\n        } \n\t\t//this else block will handle the edge case when we need to increase the array length based on k value\n\t\telse {\n            res.push( k % 10);\n            k = Math.trunc(k / 10);\n        }\n    }\n    return res.reverse();  \n}\n//  we can devide this question in two parts based on the fact that do we need extra space for the carry see e.g 2\n/**\n * e.g 1: - [1,2,6,3] & k = 516 || No Extra space needed\n * let i = 3 (num.length - 1);\n * step 1: (inside first if block cz 3 >= 0)\n * \t\t\tnum[3] + 516 = 519;\n * \t\t\t519 % 10 = 9;\n * \t\t\tres = [9];\n * \t\t\tk = (519/10) = 51;\n * \t\t\ti-- ==> 2;\n * step 2: (inside first if block cz 2 >= 0)\n * \t\t\tnum[2] + 51 = 57;\n * \t\t\t57 % 10 = 7;\n * \t\t\tres = [9, 7];\n * \t\t\tk = (57/10) = 5;\n * \t\t\ti-- ==> 1;\n * step 3: (inside first if block cz 1 >= 0)\n * \t\t\tnum[1] + 5 = 7;\n * \t\t\t7 % 10 = 7;\n * \t\t\tres = [9, 7, 7];\n * \t\t\tk = (7/10) = 0;\n * \t\t\ti-- ==> 0;\n * step 4: (inside first if block cz 0 >= 0)\n * \t\t\tnum[0] + 0 = 1;\n * \t\t\t1 % 10 = 1;\n * \t\t\tres = [9, 7, 7, 1];\n * \t\t\tk = (1/10) = 0;\n * \t\t\ti-- ==> -1; (first if consition will be false it will     * never going to the 2nd if bcz k is already 0)\n * in this case we need to reverse this array to get the result \n * Answer - [9, 7, 7, 1].reverse() => [1, 7, 7, 9]\n */\n\n/**\n * e.g 1: - [9, 9, 9] & k = 1 || Extra space needed\n * let i = 2 (num.length - 1);\n * step 1: (inside first if block cz 2 >= 0)\n * \t\t\tnum[2] + 1 = 10;\n * \t\t\t10 % 10 = 0;\n * \t\t\tres = [0];\n * \t\t\tk = (10/10) = 1;\n * \t\t\ti-- ==> 1;\n * step 2: (inside first if block cz 1 >= 0)\n * \t\t\tnum[1] + 1 = 10;\n * \t\t\t10 % 10 = 0;\n * \t\t\tres = [0, 0];\n * \t\t\tk = (10/10) = 1;\n * \t\t\ti-- ==> 0;\n * step 3: (inside first if block cz 0 >= 0)\n * \t\t\tnum[0] + 1 = 10;\n * \t\t\t10 % 10 = 0;\n * \t\t\tres = [0, 0, 0];\n * \t\t\tk = (10/10) = 1;\n * \t\t\ti-- ==> -1; (loop will break)\n * step 4: (inside SECOND if block cz k is still 1 >= 0 and i = -1)\n * \t\t\t(k value is 1) 1 % 10 = 1;\n * \t\t\tres = [0, 0, 0, 1];\n * \t\t\tk = (1/10) = 0; ( k value finally 0 NO MORE ELEMENTS TO *ADD)\n * Answer - res.reverse() => [1, 0, 0, 0]\n */\n\n```
['JavaScript']