Skip to content

Conversation

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

Both of these work, but see my notes on the time complexity. Overall nice work!

index_1 = 0
array.times do
if list[index_1] == list[index_1 + 1]
list.delete_at(index_1)

Choose a reason for hiding this comment

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

Actually delete_at will remove the element at index_1 by shifting all the subsequent elements left by one index. So it's an O(n) method. Since you have it nested in a loop running n times. This is actually an O(n2) method.


# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: o(n^2)

Choose a reason for hiding this comment

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

This is actually O(mn) where m is the length of the strings and n is the number of strings.

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