Hack Frontend Community

Add Numbers Represented as Arrays

YandexTinkoffAvito
Write a function that takes two arrays arr1 and arr2 as input, representing numbers, and returns their sum as an array.
  • - Each element of arrays arr1 and arr2 represents one digit of the number.
  • - The result should also be represented as an array, where each element is one digit.
  • - If there are leading zeros in the result, they should be preserved.

Examples:

Input 1: [1, 2, 3], [4, 5, 6]
Output 1: [5, 7, 9]
Input 2: [5, 4, 4], [4, 5, 6]
Output 2: [1, 0, 0, 0]
Run your code to see results.