-
Notifications
You must be signed in to change notification settings - Fork 47
Space - Stephanie #28
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your solutions mostly work but have less than ideal time complexity. Think about how you can use a hash to solve them.
Take a look at my comments and let me know if you have any questions.
@@ -1,3 +1,3 @@ | |||
def intersection(list1, list2) | |||
raise NotImplementedError, "Intersection not implemented" | |||
intersect = list1 & list2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works as it uses a feature of Ruby. Do think about how you'd solve it with a hash.
letter_hash = {} | ||
string.chars.map do |char| | ||
letter_hash["#{char}"] = string.count(char) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string.count(char)
is an O(n) operation, so that makes this a total of O(n^2) operation.
It could be better doing this:
letter_hash["#{char}"] = string.count(char) | |
letter_hash["#{char}"] = letter_hash["#{char}"].nil? ? 1 : letter_hash["#{char}"] + 1 |
@@ -1,4 +1,17 @@ | |||
|
|||
def palindrome_permutation?(string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but see my note below.
return false if string1.length != string2.length | ||
|
||
string1.chars.each do |char| | ||
if string2.include?(char) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.include?
is an O(n) operation, making this an O(n^2) method. Can you think of a better way to do this with a hash?
@@ -1,4 +1,14 @@ | |||
|
|||
def permutations?(string1, string2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails for heelo
and hello
, and it's more than a little inefficient.
No description provided.