Given an encoded Linked List which is encoded using the Run Length Encoding algorithm. The task is to decode the given linked list and generate the input string.
Run Length Encoding: In run length encoding, the input string is encoded by replacing a substring of repeated character in the string by the character followed by its count. If the character is single and is non-repeating than it’s count is not added. For Example, if the input string is “wwwwaaadexxxxxx”, then the function should return “w4a3dex6”
Input : List = a->5->b->r->3->NULL
Output : string = “aaaaabrrr”
From the linked list, the character is ‘a’ and it’s count is 5 so the character is repeated 5 times.
The next character is ‘b’ and the next character to it is not a number hence the character ‘b’ is repeated only once.
The next character is ‘r’ and the count is 3 hence the character is repeated 3 times.
Input : List = a->b->r->3->a->3->NULL
Output : string = “abrrraaa”
- Traverse through the linked list.
- Store the current character in a variable c.
- Check if the next node is a number and store the number in count else count is 1.
- Append the character c to the list count times.
Below is the implementation of the above approach:
- Length of longest palindrome list in a linked list using O(1) extra space
- Check whether the length of given linked list is Even or Odd
- Find length of loop in linked list
- Find Length of a Linked List (Iterative and Recursive)
- Create new linked list from two given linked list with greater element at each node
- Convert singly linked list into circular linked list
- Merge a linked list into another linked list at alternate positions
- Difference between Singly linked list and Doubly linked list
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Convert Singly Linked List to XOR Linked List
- Check if a linked list is Circular Linked List
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Create a linked list from two linked lists by choosing max element at each position
- Huffman Decoding
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.