4ms (Beats 90.00%)🔥🔥|| Full Explanation✅|| Breadth First Search✅|| C++|| Java|| Python3
Intuition :\n- Here we have to add a non-negative integer k to an array of non-negative integers num, where each element in num is between 0 and 9 (inclusive), 
# Intuition :\n- Here we have to add a non-negative integer k to an array of non-negative integers num, where each element in num is between 0 and 9 (inclusive), and returning the result as a list of integers.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Explanation to Approach :\n- First, iterate over each element in num and compute the sum of the corresponding digit in num and k. \n- Then store the ones digit of the sum in a new list called ans.\n- If the sum of the two digits is greater than 9, "carrie over" the tens digit to the next iteration of the loop.\n- If k still has remaining digits, they are also added to the ans list. \n- Finally, the resulting list ans is returned.\n# Look at this Example:\n- Let\'s say we have an array num containing the numbers [1, 2, 3, 4] and we want to add the integer k = 567 to it. The expected result would be a list [1, 7, 9, 1].\n# Here\'s how the algorithm works step by step :\n- Starting from the end of the array, we begin by adding the last element of num and k. This gives us 4 + 7 = 11. The ones digit, which is 1, is added to a new list ans and the tens digit, which is 1, is carried over to the next iteration.\n- The next element of num is 3. We add 3 to the carried over tens digit, which gives us 3 + 1 = 4. The ones digit, which is 4, is added to the front of ans, and the tens digit, which is 0, is carried over to the next iteration.\n- The next element of num is 2. We add 2 to the carried over tens digit, which gives us 2 + 0 = 2. The ones digit, which is 2, is added to the front of ans, and the tens digit, which is 0, is carried over to the next iteration.\n- The last element of num is 1. We add 1 to the carried over tens digit, which gives us 1 + 0 = 1. The ones digit, which is 1, is added to the front of ans, and the tens digit, which is 0, is carried over to the next iteration.\n- At this point, we have finished iterating over all elements of num. If there is still a carried over tens digit, it is added to the front of ans. But since the carried over digit is 0, this step doesn\'t do anything in our example.\n- Finally, we return the ans list, which contains the result [1, 7, 9, 1].\n- So, this code adds 567 to the array [1, 2, 3, 4] and returns the list [1, 7, 9, 1].\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity :\n- Time complexity : O(max(N, log(k)))\n```\nReason  : Because the algorithm iterates over each element \nin num once and may iterate over the digits of k up to log(k) \ntimes, depending on the size of k. \n```\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity : O(max(N, log(k)))\n```\nReason  : Because it creates a new list ans to store the result.\n```\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n# Please Upvote\uD83D\uDC4D\uD83D\uDC4D\n```\nThanks for visiting my solution.\uD83D\uDE0A\n```\n# Codes [C++ |Java |Python3] \n```C++ []\nclass Solution \n{\n public:\n  vector<int> addToArrayForm(vector<int>& num, int k) \n  {\n    for (int i = num.size() - 1; i >= 0; --i) \n    {\n      num[i] += k;\n      k = num[i] / 10;\n      num[i] %= 10;\n    }\n    while (k > 0) {\n      num.insert(begin(num), k % 10);\n      k /= 10;\n    }\n    return num;\n  }\n};\n```\n```Java []\nclass Solution \n{\n  public List<Integer> addToArrayForm(int[] num, int k) \n  {\n    List<Integer> ans = new LinkedList<>();\n    for (int i = num.length - 1; i >= 0; --i) {\n      ans.add(0, (num[i] + k) % 10);\n      k = (num[i] + k) / 10;\n    }\n    while (k > 0) {\n      ans.add(0, k % 10);\n      k /= 10;\n    }\n    return ans;\n  }\n}\n```\n```Python3 []\nclass Solution:\n  def addToArrayForm(self, num: List[int], k: int) -> List[int]:\n    for i in reversed(range(len(num))):\n      k, num[i] = divmod(num[i] + k, 10)\n\n    while k > 0:\n      num = [k % 10] + num\n      k //= 10\n\n    return num\n```\n# Please Upvote\uD83D\uDC4D\uD83D\uDC4D\n![ezgif-3-22a360561c.gif](https://assets.leetcode.com/users/images/783ed385-9d4d-4bec-95a2-86d4de605639_1676438010.7088408.gif)\n
['Math', 'Python', 'C++', 'Java', 'Python3']