AMAZON & MICROSOFT Question – Solved

8 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

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |