CtCI-6th-Edition-JavaScript icon indicating copy to clipboard operation
CtCI-6th-Edition-JavaScript copied to clipboard

Rewrite 1.6 to have clearer algorithm and fix bug

Open heytonytan opened this issue 7 years ago • 4 comments

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

heytonytan avatar May 22 '17 07:05 heytonytan

@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 :)

heytonytan avatar May 22 '17 07:05 heytonytan

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!

heytonytan avatar May 23 '17 08:05 heytonytan

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.

noahjahn avatar Apr 25 '21 22:04 noahjahn

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

dawsbot avatar Apr 26 '21 00:04 dawsbot