Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
Well remove_duplicates works, although your time complexity is off. The longest prefix does not work. See my notes on things and let me know if you have questions.
| j = 1 | ||
| until list[j] == nil | ||
| if list[i] == list[j] | ||
| list.delete_at(list[j]) |
There was a problem hiding this comment.
delete_at removes an element by shifting all subsequent elements left by one index. So it's an O(n) method. Since it's nested inside a loop running n times, remove_duplicates is an O(n2) method.
| characters << word.chars | ||
| end | ||
|
|
||
| characters.each do |item| |
There was a problem hiding this comment.
This isn't working, take a look at the loops a bit. You can fairly comfortably do this by having one loop go through all the words, and the 2nd looping through the letters in the 1st word. When you find a letter than not all the words have in the right position, you've found your prefix.
No description provided.