Update appNew update is available. Click here to update.
About
My Stats
EXP gained
yellow-spark
480
Level
3 (Seasoned)
Community stats
Discussions
0
Upvotes
1
Know more
10
Total problems solved
8
Easy
2
Moderate
0
Hard
0
Ninja
Jan Jan Feb Feb Mar Mar Apr Apr May May Jun Jun Jul Jul Aug Aug Sep Sep Oct Oct Nov Nov Dec Dec

Current streak:

0 days

Longest streak:

3 days

Less

More

Discussions
Java _ Encode the Message
Interview problems

import java.util.* ;

import java.io.*; 

public class Solution {

    public static String encode(String message) 

    {

        

        StringBuilder res=new StringBuilder("");

        int p=1;

        for(int i=0;i<message.length()-1;i++)

        {

        

                if(message.charAt(i)==message.charAt(i+1))

                {

                    p++;

                    

                }

                else{

                    res.append(message.charAt(i));

                    res.append(p);

                    p=1;

                }

                

    

                    

        }

        res.append(message.charAt(message.length()-1));

                    res.append(p);

        

        return res.toString();

        

    }

}

profile
Pavan Kalyan Kuncha
Published On 22-Nov-2023
17 views
0 replies
1 upvotes