AMAZON & MICROSOFT Question – Solved

5 Live
String Encoding Encode a given string by collapsing consecutive instances of a single character into two pieces of information: the number of instances and the character. Note that even single characters should be run-length encoded. If the string is empty, return an empty string. Your implementation should work on all alphanumeric characters. Function Description Complete the function collapselnput which takes a string input as a parameter and returns the compressed string. Sample Input: GGGGGrrrrrrrrrrrrttt Sample Output: 5G14r3t Explanation: There are 5 'G' characters, then there are 14 'r's, then there is 1 't'.

Asked in: AMAZON MICROSOFT

Image of the Question

Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |