Add Two Numbers Given as Digit Arrays
Updated
Problem statement
You get two numbers written out as arrays of digit characters, a and b, with the most significant digit first: ['3','5','9'] is 359. Neither number is negative.
Produce the digits of their sum the same way. Do not add leading zeros: the only answer that starts with '0' is ['0'], for a sum of zero.
Function
addDigitArrays(a: char[], b: char[]) → char[]Examples
Example 1
a = ["3","5","9"]b = ["1","2","8","4"]return = ["1","6","4","3"]Line the digits up from the right: 9 + 4 = 13, write 3 and carry 1; 5 + 8 + 1 = 14, write 4, carry 1; 3 + 2 + 1 = 6; the 1 of 1284 has no partner. The total is 1643.
Example 2
a = ["8","1","7","2"]b = ["2","9","3","1"]return = ["1","1","1","0","3"]The column sums from the right are 3, 10, 11 and 11 once carries are added in, so the written digits are 3, 0, 1, 1. A carry is still left after the leftmost column, so it becomes a new front digit: 8172 + 2931 = 11103.
Example 3
a = ["0"]b = ["8","0","6"]return = ["8","0","6"]Adding 0 changes nothing, so the answer is the digits of 806, including its inner zero.
Example 4
a = ["0"]b = ["0"]return = ["0"]Zero plus zero is zero. It comes back as ['0'], one character, and never as an empty array.
Constraints
1 <= a.length, b.length <= 1000- Every character is a digit from
'0'to'9'. - Neither array starts with
'0'unless it is exactly['0'].
More Capital One Onsite Interview questions
- Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
- Sort ColorsONSITE INTERVIEW · Seen Oct 2026
- Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
- Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
- Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
- Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
- Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
- Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
- Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025
Similar questions at other companies
- Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
- Bounded Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
- Generate an Unbiased Bit from a Biased CoinGoogle · ONSITE INTERVIEWGoogle interview questions
- Retry with an Attempt LimitOracle · ONSITE INTERVIEWOracle interview questions
- Extract Error Log ContextFlexTrade · ONSITE INTERVIEWFlexTrade interview questions
- Moving Cost by Volume and CategoryWayfair · ONSITE INTERVIEWWayfair interview questions
- Caesar Cipher with a Precomputed AlphabetAmazon · ONSITE INTERVIEW
- BitFont - Render a Kerned PairStripe · ONSITE INTERVIEWStripe interview questions
- Estimate Pi from Uniform SamplesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Add Two Numeric Strings with CarryZipRecruiter · ONSITE INTERVIEWZipRecruiter interview questions
Capital One interview experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences
- Capital One TDP Agentic Power Day: 25 Experiences (Part 1 of 2)