-
Notifications
You must be signed in to change notification settings - Fork 47
Alex - Time #39
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?
Alex - Time #39
Conversation
CheezItMan
left a comment
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.
Good work, you hit most of all the learning goals here. Well done.
Take a look at my comments and let me know if you have any questions.
| crossroads = [] | ||
|
|
||
| list1.each do |n| | ||
| crossroads << n if list2.include?(n) != false |
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 and you have this in a loop...
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
|
|
||
| def intersection(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.
This works, but it's O(n * m) in time complexity. Using a hash you can get this to O(n + m) time complexity which is much better.
I encourage you to think about how to do this.
| def palindrome_permutation?(string) | ||
| raise NotImplementedError, "palindrome_permutation? not implemented" | ||
| end | ||
| while string.empty? |
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.
while?
| while string.empty? | |
| if string.empty? |
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
|
|
||
| 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.
👍
| perm = string1.chars | ||
| mutant = string2.chars | ||
| mindflayer = {} |
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.
I like DND too, but these aren't the best variable names.
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
|
|
||
| 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 works only if the count of each letter is the same. It returns true however for heelo and hello.
Apologies that this is late--meant to submit around 6:30, and I just remembered I forgot to do the PR step.