FastPrepAdd Two Numbers II

Add Two Numbers II

Bloomberg LP logoBloomberg LP● MediumNEW GRADFULLTIMEPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

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.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public ListNode addTwoNumbersForward(ListNode l1, ListNode l2) {
  // Write your code here.
}
l1[7,2,4,3]
l2[5,6,4]
expected[7,8,0,7]
Checking account…