Skip to content

Conversation

@CEsGutierrez
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.

The first one works well, but see my notes on the time complexity. The second, longest prefix, does not, but I had to work to find an example, I ended up updating AdaGold with the example that causes yours to fail.

Overall not bad, check out my notes and let me know any questions you have.

# Time Complexity: ?
# Space Complexity: ?
require 'pry'
# Time Complexity: O(n) - as array size grows, the evaluation grows at the same rate

Choose a reason for hiding this comment

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

Since delete_at shifts all subsequent letters over one value to the left, and has a time complexity of O(n), your algorithm is O(n)

k = 0 # I am the last characer that matched

# binding.pry
until j == max_length || i + 1 == strings.length do

Choose a reason for hiding this comment

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

The order you are looking at things won't work for everything, consider:

strings = ["carborator","carvonulted","carsome", "calsome"]

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