Prepin
Log in

Given two integers represented as arrays, return their product in the same array format.

Approach / Explanation

The task requires you to create a function that multiplies two integers represented as arrays and returns the result in the same array format. The focus here is on how integers are formatted as arrays. For example, an integer like 123 would be represented as [1, 2, 3]. In a similar manner, 5678 would be represented as [5, 6, 7, 8], and so forth. The function should: Convert the arrays back into integers, Perform the multiplication of these integers, Then convert the resulting product back into an array format before returning it. Keep in mind that you cannot simply concatenate the array elements and cast them to an integer due to the potential for leading zeroes in the output. Consider how to manage this aspect when developing your solution.

Suggested Answer

We have two arrays, [1, 2, 3] and [4, 5, 6], which represent the numbers 123 and 456, respectively. First, we need to convert these arrays into their integer forms, resulting in the numbers 123 and 456. Next, we multiply these integers, yielding a product of 56188 for 123 and 456. Lastly, we convert this integer back into an array format, giving us [5, 6, 1, 8, 8] as our final result.

Alternative Answer

We have two arrays, [9, 9, 9] and [1, 0, 0, 0], which represent the numbers 999 and 1000, respectively. First, we will convert these arrays into integers, resulting in the values 999 and 1000. Next, we will multiply these integers together. The product of 999 and 1000 is 999000. Finally, we will convert this integer back into array format, yielding [9, 9, 9, 0, 0, 0] as our final result. It's important to note that simply concatenating the elements of the arrays wouldn't have been sufficient, as that would not account for the two trailing zeros in the final output, which would be lost if we converted the arrays to a string and then to an integer.

Question Details

Difficulty & Category

Medium
technical

Companies

Google

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin LLC · Philadelphia, PA · All rights reserved.