Reported January 2022
Bloombergstack

Add Two Numbers II

Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Bloomberg OA. Under 2s to a working solution.
Founder's read

Bloomberg reported this one in January 2022, and it's grade-school addition with a linked list twist. The digits come most-significant first, you can't reverse or mutate the inputs, and the carry has to flow backward through a list that only moves forward. If you've got an OA invite, expect to be judged on how cleanly you handle that mismatch. The pattern is stack-based, and once you see it the code is short. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the idea here is simple enough to hold in your head.

The problem

Two nonnegative integers are stored in forward digit order in linked lists l1 and l2. Return their sum as a forward-order digit list.
Do not reverse or mutate the input lists.

Function
addTwoNumbersForward(l1: ListNode, l2: ListNode) → ListNode

Examples
Example 1
l1 = [7,2,4,3]
l2 = [5,6,4]
return = [7,8,0,7]
7243 + 564 = 7807.
Example 2
l1 = [9,9]
l2 = [1]
return = [1,0,0]
The final carry becomes the new head.

Constraints
Each list has between 1 and 100 nodes.
Every node value is a decimal digit.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The problem really reduces to this: addition starts at the least significant digit, but your lists start at the most significant. Since you can't reverse or mutate, push every node value of each list onto its own stack. Then pop from both, add the digits plus carry, and build the result by prepending each new node to the front of the output list. That prepending trick means the answer comes out in forward order with no reversal step. The common pitfall is forgetting the final carry. Example 2, [9,9] plus [1], needs a new head node of 1. Another trap is stopping when one stack empties. Keep looping while either stack has values or carry is nonzero. Time and space are both O(n + m). If you blank during the live OA, StealthCoder is the hedge that surfaces this stack approach so you can still ship a clean solution.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Add Two Numbers II cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as add two numbers ii. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Bloomberg's OA.

Bloomberg reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Add Two Numbers II FAQ

How hard is Add Two Numbers II really?+

It's medium, and easier than it looks once you spot the stack idea. The logic is basic addition with a carry. Most people lose points on edge cases like a leftover carry or lists of different lengths, not on the core algorithm.

What's the trick to solving it without reversing the lists?+

Use two stacks. Push all digits of each list, then pop to process from the least significant digit. Build the result by inserting each new node at the head, so the final list is already in forward order. No mutation of the inputs is needed.

Can I convert the lists to integers and add them?+

Not safely. Each list can hold up to 100 digits, which overflows standard integer types in many languages. Even where big integers exist, it dodges the point of the question. Stick with digit-by-digit addition and a carry.

What edge cases should I test before submitting?+

Test the final carry case like [9,9] plus [1] giving [1,0,0]. Test lists of very different lengths, single-node lists, and a case where both are zero. Make sure your loop continues while either stack has items or the carry is nonzero.

How do I prepare for this in 48 hours?+

Write the two-stack solution from scratch twice and trace Example 1 by hand. Then do the follow-up of solving it without extra stacks, using recursion or length alignment. Linked list plus carry problems show up repeatedly, so the pattern transfers well.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Bloomberg.

OA at Bloomberg?
Invisible during screen share
Get it