PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates linked list manipulation and numerical addition represented in forward-order digit encoding, testing competency in handling digit-by-digit arithmetic, carry propagation, and edge cases such as differing list lengths and final carry.

  • medium
  • Bloomberg
  • Coding & Algorithms
  • Software Engineer

Add Two Forward-Order Lists

Company: Bloomberg

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Implement a function that adds two non-negative integers represented by singly linked lists. - Each node stores a single digit. - The digits are stored in **forward order**, so the head contains the most significant digit. - The input lists do not have leading zeros unless the number itself is zero. - Return the sum as a new linked list in **forward order**. You should define the `ListNode` structure yourself and handle common edge cases such as different list lengths and a final carry. Example: - `7 -> 2 -> 4 -> 3` represents 7243 - `5 -> 6 -> 4` represents 564 - Output: `7 -> 8 -> 0 -> 7` because 7243 + 564 = 7807 Follow-up: Can you solve it **without reversing the input lists**, if extra space is allowed?

Quick Answer: This question evaluates linked list manipulation and numerical addition represented in forward-order digit encoding, testing competency in handling digit-by-digit arithmetic, carry propagation, and edge cases such as differing list lengths and final carry.

Two non-negative integers are represented by singly linked lists where each node stores a single digit and the digits are stored in **forward order** (the head holds the most significant digit). For this console the lists are passed as integer arrays of digits, head first. Return the sum as a new array of digits in **forward order**. Rules: - Each element is a single digit `0-9`. - An input has no leading zeros unless the number itself is zero (in which case it is `[0]`). - Handle different lengths and a final carry. The empty array `[]` represents the value `0`. Example: - `[7, 2, 4, 3]` represents 7243 - `[5, 6, 4]` represents 564 - Output: `[7, 8, 0, 7]` because 7243 + 564 = 7807 Follow-up: solve it **without reversing the input lists** if extra space is allowed (e.g. push digits onto two stacks, or align by length and build the result back-to-front).

Constraints

  • 0 <= len(l1), len(l2)
  • Each digit is in the range 0-9.
  • No leading zeros unless the number is exactly zero ([0]).
  • The empty list [] is treated as the value 0.

Examples

Input: ([7, 2, 4, 3], [5, 6, 4])

Expected Output: [7, 8, 0, 7]

Explanation: 7243 + 564 = 7807.

Input: ([0], [0])

Expected Output: [0]

Explanation: 0 + 0 = 0; the result keeps a single zero digit.

Input: ([9, 9, 9], [1])

Expected Output: [1, 0, 0, 0]

Explanation: 999 + 1 = 1000; the carry propagates through every digit and adds a new most-significant digit.

Input: ([5], [5])

Expected Output: [1, 0]

Explanation: 5 + 5 = 10; single-digit inputs produce a carry.

Input: ([1, 2, 3], [])

Expected Output: [1, 2, 3]

Explanation: The empty list is 0, so 123 + 0 = 123.

Input: ([2, 4, 9, 5, 6], [7, 5, 3, 4])

Expected Output: [3, 2, 4, 9, 0]

Explanation: 24956 + 7534 = 32490; different lengths with multiple internal carries.

Input: ([0], [9, 9])

Expected Output: [9, 9]

Explanation: 0 + 99 = 99; a zero operand leaves the other number unchanged.

Hints

  1. Forward order means the head is the most significant digit, so naive node-by-node addition would add the wrong digits together — you must align the numbers by their least significant ends.
  2. One clean approach: convert each list to its integer value, add, then peel digits off the sum from least to most significant and reverse the result.
  3. To avoid reversing the inputs (the follow-up), push each list's digits onto a stack (or compare lengths and pad), then add from the back, carrying as you go, and prepend each result digit.
Last updated: Jun 26, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Minimize Travel Assignment Cost - Bloomberg (medium)
  • Determine Balloon Popping Time - Bloomberg (medium)
  • Solve meeting and tree problems - Bloomberg (easy)
  • Minimize travel cost with two cities - Bloomberg (easy)
  • Check connectivity between two subway stations - Bloomberg (easy)