Skip to content

[FEATURE REQUEST] String Compression #3911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Swarga-codes opened this issue Mar 8, 2023 · 6 comments
Closed

[FEATURE REQUEST] String Compression #3911

Swarga-codes opened this issue Mar 8, 2023 · 6 comments

Comments

@Swarga-codes
Copy link
Contributor

What would you like to Propose?

I would like to add the string compression algorithm that compresses and returns the size of a string as per the example given below:
Input:
Here, we take a string of characters,
char[] chars = ["a","a","b","b","c","c","c"]

Output: 6

Explanation: The groups are "aa", "bb", and "ccc". This compresses to "a2b2c3", which has a size of 6. Also, if any character has a single occurence we don't write it as "a1" or "b1" rather we just add that character to the resulting string.

Issue details

I was going through the strings folder, and didn't find this algorithm and wanted to contribute this algorithm to this repo.

Additional Information

I was struggling to solve the question based on this on leetcode and finally managed to solve it on my own, that is, a leetcode accepted solution and would love to share this solution and add it to the repo. Thank you!

@siriak
Copy link
Member

siriak commented Mar 8, 2023

Is it run length encoding? If so, feel free to implement it

@Swarga-codes
Copy link
Contributor Author

My current code returns the encoded length if you want the encoded string I can modify accordingly.

@siriak
Copy link
Member

siriak commented Mar 9, 2023

Yes, please. The purpose of any encoding is to encode the text.

@Swarga-codes
Copy link
Contributor Author

I modified my algorithm that returns the encoded string and created a pull request for this issue, can you please check?

@Swarga-codes
Copy link
Contributor Author

@siriak I made the necessary changes as u told on the PR, the changes include:

  1. Reduce the size of code by dividing the code into smaller functions
  2. Removed unnecessary comments
  3. Removed the main
  4. Included some Junit test cases for the code which you can access in the tests folder
    Can you please check the PR now?

@Swarga-codes
Copy link
Contributor Author

@siriak can you please check, I have made the necessary changes in my PR?

@siriak siriak closed this as completed in 86c9314 Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants