Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions lib/practice_exercises.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct!

# Space Complexity: O(1)
def remove_duplicates(list)
raise NotImplementedError, "Not implemented yet"
i = 1
list.each do |character|
if character == list[i]
list.delete_at(i)
end
i += 1
end
return list
end

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n^2)
# Space Complexity: 0(1)
def longest_prefix(strings)
raise NotImplementedError, "Not implemented yet"
max_prefix = strings.min

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe use min_by so you can get the smallest by length.

max_length = max_prefix.length
strings.each do |string|
while string[0..max_length - 1] != max_prefix[0..max_length - 1]
max_length -= 1
end
end
prefix = max_prefix[0..max_length - 1]
end