You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed a bug in the solution code for ch1-q1-solution2, specifically the function hasUniqueCharactersSort(). We cannot sort a string directly in Javascript - we have to convert the string to an array and then perform the sorting operation on it.
I have fixed the bug. Also, I have attached 2 screenshots below that show the reproduced bug and that the fix works.
Thank you for providing these solutions. Overall, they are very helpful : )
In fact in this repository, many test code ([ch\d-q\d].spec.js) involving string manipulation split the primitive string into an array of string, then pass it as argument into function (in [ch\d-q\d].js): func(arg.split('')).
String in JavaScript is immutable, but Array is on the contrary. It's interesting and we need to be careful to discuss the space complexity of the method. Here, if we assume the input is already in 'array form', then we could say that the space complexity is O(1), but if the question indeed give us 'inputString' as our start point, in my opinion, for usage of sort(), split() takes inevitable O(n) for new array.
Another similar situation is in ch1-q3.js:
url[j] = '0';
url[--j] = '2';
url[--j] = '%';
This kind of assignment operation is only available to array, if we assume the input is already an array, the space complexity could be O(1), but if the input we have is a primitive string, I think it should be O(n) because of splitting.
If the input is indeed a string and not an array. The worse case complexity would be O(n^2) as sort would have dependency on an array(a data structure).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello,
I hope you are doing well.
I noticed a bug in the solution code for ch1-q1-solution2, specifically the function
hasUniqueCharactersSort(). We cannot sort a string directly in Javascript - we have to convert the string to an array and then perform the sorting operation on it.I have fixed the bug. Also, I have attached 2 screenshots below that show the reproduced bug and that the fix works.
Thank you for providing these solutions. Overall, they are very helpful : )
Best,
Noor
Before the fix:

After the fix:
