Login

All Problems

Problem title

Difficulty

Avg time to solve

First Missing Positive

Moderate

18 mins

Maximum Subarray Sum

Hard

35 mins

XOR Query

Moderate

10 mins

Rat In a Maze All Paths

Moderate

40 mins

Reverse Blocks

Hard

56 mins

Sudoku?

Moderate

40 mins

Swap Two Numbers

Easy

10 mins

Flip Bits

Easy

15 mins

Add Two Numbers As Linked Lists ll

Moderate

10 mins

Alien dictionary

Hard

46 mins

Problem

Submissions

92

Avg. time to solve

10 min

Success Rate

80%

Problem Statement

```
If the first linked list is 1 -> 2 -> 3 -> 4 -> 5 -> NULL and the second linked list is 4 -> 5 -> NULL.
The two numbers represented by these two lists are 12345 and 45, respectively. So, adding these two numbers gives 12390.
So, the linked list representation of this number is 1 -> 2 -> 3 -> 9 -> 0 -> NULL.
```

```
The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains the elements of the first linked list separated by a single space and terminated by -1. Hence, -1 would never be a list element.
The second line of each test case contains the elements of the second linked list separated by a single space and terminated by -1. Hence, -1 would never be a list element.
```

```
For each test case, return the head of linked list after summation. The elements of the linked list must be terminated by -1.
```

```
You don't need to print anything, it has already been taken care of. Just implement the given function.
```

```
Try to solve this problem in linear time complexity and constant space complexity.
```

```
1 <= T <= 100
1 <= L <= 5000
0 <= data <= 9 and data != -1
Where 'L' is the number of nodes in either of the two Linked List and 'data' is the element value in a node of the linked list.
Time limit: 1 sec
```

```
2
1 1 -1
9 9 9 -1
2 4 -1
5 3 -1
```

```
1 0 1 0 -1
7 7 -1
```

```
In test case 1, we are adding 11 and 999 to get 1010.
In test case 2, we are adding 24 and 53 to get 77.
```

```
2
3 8 1 2 9 -1
9 8 2 9 -1
1 9 0 -1
8 1 0 -1
```

```
4 7 9 5 8 -1
1 0 0 0 -1
```

```
In test case 1, we are adding 38129 and 9829 to get 47958.
In test case 2, we are adding 190 and 810 to get 1000.
```

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Language

Change Theme

Solution submission not allowed

Save Code

Reset Code