FastPrepAdd Two Numbers

Add Two Numbers

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

Two nonnegative integers are stored in reverse digit order in linked lists l1 and l2. Each node stores one digit.

Return their sum as a reverse-order digit linked list. Neither input has leading zeroes except the number zero.

Function

addTwoNumbers(l1: ListNode, l2: ListNode) → ListNode

Examples

Example 1

l1 = [2,4,3]l2 = [5,6,4]return = [7,0,8]

342 + 465 = 807.

Example 2

l1 = [9,9,9]l2 = [1]return = [0,0,0,1]

The final carry creates a new node.

Constraints

  • Each list has between 1 and 100 nodes.
  • Every node value is between 0 and 9.

More Bloomberg LP problems

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