-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
run length encoding #109
Comments
The following does not work in all cases. so solution has to be better than this:
` |
The solution that is immediately obvious to me is to only append the counter variable to the string if counter > 1 (there was a run). if(counter > 1) compressed.append(counter);
compressed.append(input.charAt(i)); If there are no runs in a string, the output will simply be the input string. Without much context, I'm not sure if this fits the criteria of the problem, because it's not truly RLE, but it is a potential solution. |
Uber:
Classic run length encoding problem. Given an alphanumeric input - you are to apply run length encoding to encode the input argument.
Caveat:
The encoded value has to be <= input length.
Should pass test case for following inputs:
abcde
141414
The text was updated successfully, but these errors were encountered: