CtCI-6th-Edition-JavaScript
CtCI-6th-Edition-JavaScript copied to clipboard
Rewrite 1.6 to have clearer algorithm and fix bug
Current bug: original string is not returned in instance of compressed string being same length as original string.
@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 :)
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!
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.
I don't maintain this anymore, sorry folks. Hopefully, you can find someone at @careercup 🙏