Skip to content

Conversation

@north108
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants