Problem title
Difficulty
Avg time to solve

Increasing Subsegment
Moderate
15 mins
Minimum time
Moderate
15 mins
X OR Y
Easy
15 mins
Easy
10 mins
Sum Of Squares Of First N Natural Numbers
Easy
15 mins
Find All Anagrams in a String
Easy
15 mins
Finding Binary In Decimal
Easy
15 mins
Board Cutting
Moderate
10 mins
XOR Property
Easy
15 mins
Counting Pairs
Moderate
35 mins
4

# Add First and Second Reversed Half

Difficulty: MEDIUM
Contributed By
Avg. time to solve
42 min
Success Rate
60%

Problem Statement

#### Note:

``````1. When 'N' is odd consider the middle element to be part of 1st half.
2. The sum should not contain any leading zero, except the number 0 itself.
``````

#### For example:

``````Given a Linked List: 1-2-3-4-5-5-6

First half: 1-2-3-4
Reversed second half: 6-5-5

Output linkedlist: 1-8-8-9 = (1234 + 655 = 1889)
``````

``````Can you add both halves without finding the length of LinkedList and in O(1) space?
``````
##### Input format :
``````A single line of input contains the elements of the singly linked list separated by a single space and terminated by -1.
``````
##### Output format :
``````For each input, print a single line containing a string denoting the required sum.
``````
##### Note:
``````You do not need to print anything; it has already been taken care of. Just implement the given function.
``````
##### Constraints :
``````0 <= 'N' <= 10 ^ 5
0 <= 'DATA' <= 9

Where 'N' is the number of nodes in linked list and 'DATA' is the integer value in each node.

Time Limit: 1 sec
``````
##### Sample Input 1:
``````1 2 4 5 6 -1
``````
##### Sample Output 1:
``````189
``````
##### Explanation for Sample Input 1:
``````The first half of the given linkedlist is: 1-2-4
The second half of the given linkedlist is: 6-5
Sum of both parts = 124 + 65 = 189
``````
##### Sample Input 2:
``````3 9 0 1 1 0 -1
``````
##### Sample Output 2:
``````401
``````
Console