New update is available. Click here to update.

Last Updated: 22 Sep, 2021

Difficulty: Easy

```
n = 4, list: 1 -> 0 -> 1 -> 0.
```

```
Now in this example, the value in the linked list is 1010, which is 10 in Decimal.
Hence the answer is 10.
```

```
The first line contains a single integer ‘T’ denoting the number of test cases. Then each test case follows:
The first line of each test case contains an integer, ‘n’, denoting the number of nodes in the linked list.
The next ‘M’ lines of the test case contain two space-separated integers, ‘x’ and ‘y’, denoting a track between ‘x’ and ‘y’.
The last line of the test case contains ‘n + 1’ space-separated integers which are the nodes of the linked list and each line ends with -1 to indicate that the sublist is over. Thus, -1 will never be a linked list element.
```

```
For each test case, print the Decimal representation of the number.
Output for each test case will be printed in a separate line.
```

```
You are not required to print anything; it has already been taken care of. Just implement the function and return the answer.
```

```
1 <= T <= 100
1 <= N <= 3000
Time Limit: 1sec
```

The approach is simple, you have to take an integer to store the final answer, and iterate through the list and add the current element to “ans” and multiply ans by 2.

The steps are as follows:

- Take an integer “num” and initialize it with zero.
- Iterate through the list till we reach the last element:
- Multiply “num” by 2.
- Update “num = “head” -> data.
- Jump to the next node i.e. “head” = “head” -> next.

- Return “num”.

SIMILAR PROBLEMS

Deletion In Doubly Linked List

Posted: 22 Apr, 2022

Difficulty: Easy

Insertion In Doubly Linked List

Posted: 24 Apr, 2022

Difficulty: Easy

LRU Cache

Posted: 10 Sep, 2022

Difficulty: Moderate

Delete Nodes On Regular Intervals

Posted: 19 Dec, 2022

Difficulty: Ninja

Add One To Linked List

Posted: 19 Dec, 2022

Difficulty: Hard

Popular Interview Problems: