X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Subtraction in Linked List
Hard Accuracy: 40.53% Submissions: 17345 Points: 8

Given two linked lists that represent two large positive numbers. The task is to subtract the given two numbers represented by the linked list. Subtract the smaller from the larger one.

Example 1:

Input:
L1 = 1->0->0
L2 = 1->2
Output: 8 8
Explanation:  12 subtracted from 100
gives us 88 as result.

Your Task:
The task is to complete the function subLinkedList() which should subtract the numbers represented by the linked list and return the head of the linked list representing the result.

Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N).

Constraints:
1 <= Length of the Linked List <= 10000

 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Subtraction in Linked List

Output Window