Skip to content

Leaves - Elizabeth #44

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Leaves - Elizabeth #44

wants to merge 1 commit into from

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