Iterate over the input String, copying characters to a new StringBuilder object along with the repeat counts. 1. Maintain two temporary variables, one to store the last Character and the other to store its count. Initialize the last Character with first element in the Array and set its count to 1. 2. Also maintain a temporary empty StringBuilder object, to store the compressed output. 3. Iterate through the Array of Characters . If the Character at each position is equal to last Character, increment the count. Otherwise, change the last Character and initialize its count to 1. 4. Simultaneously, append to the compressed string the last Character and its count.