Ctrl K

Double the Digit Chain

Medium
A non-negative integer is stored in a singly linked list, one digit per node, most significant digit first. There are no leading zeros (except for the number 0 itself). You are given the list's head. Multiply the number by 2 and return the head of a list holding the result in the same format.
Example 1
head=list_node([2, 6, 4]) → [5, 2, 8]

The list stands for 264; 264 · 2 = 528.

Example 2
head=list_node([5, 0]) → [1, 0, 0]

50 · 2 = 100, so the answer gains a new leading digit.

Example 3
head=list_node([0]) → [0]
Constraints
  • 1 ≤ number of nodes ≤ 10⁴
  • 0 ≤ Node.val ≤ 9
  • The number has no leading zero unless it is 0 itself
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsForward Digit List Sum MediumAdding Digit Lists MediumTree Into a Right Chain MediumList Folded From Both Ends MediumPostfix Calculator Medium
loading Python…
Input
head=list_node([2, 6, 4])
Expected
[5, 2, 8]

Run checks the first 3 tests in your browser. Submit checks all 74 tests on the server, hidden ones included.