Skip to content

Rewrite 1.6 to have clearer algorithm and fix bug#16

Open
heytonytan wants to merge 1 commit intocareercup:masterfrom
heytonytan:master
Open

Rewrite 1.6 to have clearer algorithm and fix bug#16
heytonytan wants to merge 1 commit intocareercup:masterfrom
heytonytan:master

Conversation

@heytonytan
Copy link
Copy Markdown
Collaborator

@heytonytan heytonytan commented May 22, 2017

Current bug: original string is not returned in instance of compressed string being same length as original string.

…ng is not returned in instance of compressed string being same length as original string.
@heytonytan
Copy link
Copy Markdown
Collaborator Author

heytonytan commented May 22, 2017

@dawsbot did forced push in my repo to clean things up. Take a look and see if this makes sense.

Your Travis CI is also failing. I think for purposes of this repo of coding interview questions, wondering if we could consider doing away with continuous integration as the files/functions are standalone :)

Copy link
Copy Markdown
Contributor

@dawsbot dawsbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty confused at the complete change in logic. Why don't you keep the entire code the same, remove the maxCount logic, and then do the return like you have in the new code?

return answer.length < string.length ? answer : string; looks great

@heytonytan
Copy link
Copy Markdown
Collaborator Author

Hey @dawsbot, I wrote the previous version sometime back and thought that this rewrite presented the code much more cleanly with a parse-reduce approach. The logic is pretty much the same..

Thanks for taking the time!

@noahjahn
Copy link
Copy Markdown

I figured I might be able to provide some insight here (I realize this is a very old PR). I was looking at this and the original answer actually doesn't work as expected and outlined in the question in the book.

The change in logic in the return line fixes the problem.

The compressed string algorithm in the original answer is using maxCount. That maxCount is used to assume that the only scenario that would cause the function to return the same string is when there no repeating characters. That means, passing in a value like aa would return a2. But the length of both aa and a2 are the same. I would expect the function to return aa in this case.

@dawsbot
Copy link
Copy Markdown
Contributor

dawsbot commented Apr 26, 2021

I don't maintain this anymore, sorry folks. Hopefully, you can find someone at @careercup 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants