Question d’entretien chez Pegasystems

Write the C++/Java code to compress the given string it is easy question on the leetcode.