Skip to content
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

Branches - Michaela #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

michaela260
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.

Your first method works, but see my notes on the time complexity. Your second doesn't work, but I had to invent a new test to prove it. See my comments on it.

index += 1
else
if item == prev_num
list.delete_at(index)

Choose a reason for hiding this comment

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

delete_at actually shifts all the subsequent elements over 1 index. So it actually has a runtime of O(n). Since it's inside a loop running n times... Your method has a time complexity of O(n2)

status = true
check_letter = strings[0][i]
strings.each do |string|
if string[i] != check_letter

Choose a reason for hiding this comment

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

If you find a letter that won't work you can stop here because any subsequent other letters can't be in the prefix.

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(a * b) where a is the number of letters in the first word, and b is the number of words in the array
# Space Complexity: O(1)
def longest_prefix(strings)

Choose a reason for hiding this comment

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

This actually doesn't work.
Consider strings = ["carborator","carvonulted","carsome", "calsome"].

It won't work for this.

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