Timer is Running

Subtraction in Linked List
Submissions: 3746   Accuracy:


  Difficulty: Easy   Marks: 2
Associated Course(s):   Amazon SDE Test Series

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.

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains an integer N denoting the size of the first linked list (L1)  In the next line are the space-separated values of the first linked list. The third line of each test case contains an integer M denoting the size of the second linked list (L2). In the fourth line are space-separated values of the second linked list.

For each test case, the output will be space-separated values of the resultant linked list. 

User Task:
The task is to complete the function subLinkedList() which should subtract the numbers represented by the linked list.

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

1 <= T <= 100
1 <= N, M <= 10000

1 0 0
1 2

8 8

Testcase 1:
12 subtracted from 100 gives us 88 as result.


** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Amit Khandelwal
Author: Shubham Joshi 1

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.