Add to Array-Form of Integer

The array-form of an integer is the array of its digits from left to right, for example 1321 is [1,3,2,1]. Given the array-form num of an integer and an integer k, return the array-form of num + k.

30:00

Add to Array-Form of Integer
easy
Free written solution
Topics
Companies

The array-form of an integer is the array of its digits from left to right, for example 1321 is [1,3,2,1]. Given the array-form num of an integer and an integer k, return the array-form of num + k.

Example 1:
Input: {"num":[1,2,0,0],"k":34}
Output: [1,2,3,4]
Constraints:
  • 1≤num.length≤1041 \leq \text{num.length} \leq 10^4

  • 0≤num[i]≤90 \leq \text{num}[i] \leq 9

  • num has no leading zeros except for the number 0 itself.

  • 1≤k≤1041 \leq k \leq 10^4

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"num":[1,2,0,0],"k":34}

Add k = 34 to the number written as [1,2,0,0]. k itself will act as the carry.

num: 4 digits
original k = 34
k = 34
i = 3

column addition

num
1
2
0
0
+ k
3
4
=

result list (ones digit first)

[]
Variables
VariableValue
k34
DepthFunction Call
Stack empty
0/20