![]() |
VOOZH | about |
Given a Linked List as the input. The task is to encode the given linked list using Run Length Encoding. That is, to replace a block of contiguous characters by the character followed by it's count.
For Example, in Run Length Encoding "a->a->a->a->a" will be replaced by "a->5".
Note: For non-repeating nodes, do not append count 1. For example, a->b->b will be replaced by "a->b->2" and not "a->1->b->2".
Examples:
Input : List = a->a->a->a->a->b->r->r->r->NULL
Output : a->5->b->r->3->NULL
Explanation :
The character 'a' repeats 5 times.
The character 'b' repeats 1 time.
The character 'r' repeats 3 times.
Hence the output is a->5->b->r->3->NULL.Input : a->a->a->a->a->a->a->a->a->a->b->r->r->r->a->a->a->NULL
Output : a->1->0->b->r->3->a->3->NULL
Approach:
Implementation:
a 3 b r 2
Complexity Analysis:
In Place Conversion:
The idea here is to modify the existing list based on the frequency of characters rather than creating a new list if system enforces space constraint.
a 3 b r 2
Complexity Analysis: