public static void Main()
Console.WriteLine($"Compressed: {compress(_s)}");
public static string compress(string str){
int finalLength=countCompression(str);
if(finalLength > str.Length) return str;
StringBuilder sb= new StringBuilder(finalLength);
int countConsecutive = 0;
for(int i = 0; i < str.Length; i++){
if(i+1 >= str.Length || str[i] != str[i+1]){
sb.Append(countConsecutive);
private static int countCompression(string str){
int compressedLength = 0;
int countConsecutive = 0;
for(int i = 0; i < str.Length; i++){
if(i+1 >= str.Length || str[i] != str[i+1]){
compressedLength += 1 + (countConsecutive.ToString()).Length;