Encode the Message
You have been given a text message. You have to return the Run-length Encoding of the given message.
Run-length encoding is a fast and simple method of encoding strings. The basic idea is to represent repeated successive characters as the character and a single count. For example, the string "aaaabbbccdaa" would be encoded as "a4b3c2d1a2".
Input format:
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then the test cases follow:
The first and only line of each test case will contain a string denoting the message.
Note:
It's guaranteed that the message string will have no digits and consists solely of lowercase alphabetic characters.
Output format:
For each test case, print a single line containing the encoded message string.
Output for every test case will be printed in a separate line.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 10
1 <= N <= 100000
Where 'N' is the length of the message string.
Time Limit: 1 sec
CodingNinjas
author
2y
Steps:
1) Sort all the words in descending order of their lengths.
2) Initialise res with first word in the vector + "#"
3) Now we just need to find, if other words in the vector + # are substring of res...read more
CodingNinjas
author
2y
Constructive Implementation
Build the encoded string by iterating left to right counting repeated successive characters
- Create an empty encoded string 'ENCODEDMESSAGE' = “”.
- Iterate from i = 0 to N - 1 w...read more
Help your peers!
Add answer anonymously...
Top Walmart Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Walmart Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app