Skip to main content

Posts

Featured

String question 2

Problem Asked in Google  TCS Walmart Microsoft  from String  Q)  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". Solution : # include < iostream > # include < string > using namespace std ; string encode ( string & message ) { // Result string to store the encoded message string encoded = ""; // Length of the message int n = message . length (); // Edge case: if the message is empty if ( n == 0 ) { return encoded ; } // Initialize the count for the first character char currentChar = message [ 0 ] ; int count = 1 ; // Iterate through the message starting from the second char...

Latest Posts

String Question 1

Linked list 4

IFELSE IN PYTHON